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

Date Pipe formatting incorrectly (showing wrong date) #8319

Closed
cperez87 opened this issue Apr 28, 2016 · 32 comments
Closed

Date Pipe formatting incorrectly (showing wrong date) #8319

cperez87 opened this issue Apr 28, 2016 · 32 comments
Labels
area: common Issues related to APIs in the @angular/common package area: i18n freq2: medium type: bug/fix

Comments

@cperez87
Copy link

cperez87 commented Apr 28, 2016

The Date Pipe is formatting certain dates incorrectly. It is showing the wrong date when formatted.

Steps to reproduce and a minimal demo of the problem
Create a Date for April, 1, 2004 (happens with 2000 too, but not with 2016).
Display this date using {{myDate | date}} pipe.

You can use plunker sample below
http://plnkr.co/edit/H32nNiSqxJJwQ0DvYcEm

Current behavior
For April 1, 2004. It shows the formatted date as Mar 31, 2004.

Expected/desired behavior
Formatted date as Apr 1, 2004

@cperez87 cperez87 changed the title BUG: Date Pipe not showing BUG: Date Pipe formatting incorrectly (showing wrong date) Apr 28, 2016
@cperez87 cperez87 changed the title BUG: Date Pipe formatting incorrectly (showing wrong date) Date Pipe formatting incorrectly (showing wrong date) Apr 28, 2016
@CaptainCodeman
Copy link

Probably some local-time / UTC issue somewhere. It works fine from North America.

Strangely, the two dates show as having different timezones when I run it.

@cperez87
Copy link
Author

cperez87 commented Apr 28, 2016

Im on US EST.
Im seeing the following on the preview pane of the plunker sample:

Formatted: Mar 31, 2004
Actual: Thu Apr 01 2004 00:00:00 GMT-0400 (Eastern Daylight Time) 

Formatted: Apr 1, 2016
Actual: Fri Apr 01 2016 00:00:00 GMT-0400 (Eastern Daylight Time)

2000 and 2004 were leap years. Although 2016 is as well. Hence why I included these two dates.

@cperez87
Copy link
Author

cperez87 commented Apr 28, 2016

Adding 1 hour to the time returns the following:

Formatted: Apr 1, 2004
Actual: Thu Apr 01 2004 01:00:00 GMT-0400 (Eastern Daylight Time)

Hope it helps.

@CaptainCodeman
Copy link

I see this in Chrome:

Apr 1, 2004
Thu Apr 01 2004 00:00:00 GMT-0700 (MST) 
Apr 1, 2016
Fri Apr 01 2016 00:00:00 GMT-0600 (MDT)

I guess my PC isn't sure where it is so it's hedging it's bets.

@ulikoehler
Copy link
Contributor

In Europe/Chrome I see this in the Plunkr:

Formatted: Apr 1, 2004
Actual: Thu Apr 01 2004 00:00:00 GMT+0200 (CEST) 

Formatted: Apr 1, 2016
Actual: Fri Apr 01 2016 00:00:00 GMT+0200 (CEST) 

Alternate with 1 extra hour
Formatted: Apr 1, 2004
Actual: Thu Apr 01 2004 01:00:00 GMT+0200 (CEST)

@oodboo
Copy link

oodboo commented May 7, 2016

version 2.0.0.rc.1

for format:  upddate | date:'dd-MM-yyyy' 
result is: 05/07/2016 

for format : upddate | date:'dd MMM yyyy' 
result is: May 07, 2016 

for format : upddate | date:'d/MMM/yyyy' }}
result is: May 7, 2016 

for format : upddate  | date:'MMM, dd yyyy' }}
result is: May 7, 2016 

always the same ...

@natcohen
Copy link

Works with RC2... this should be closed

@vicb
Copy link
Contributor

vicb commented Jun 17, 2016

thanks

@vicb vicb closed this as completed Jun 17, 2016
@cperez87
Copy link
Author

I don't believe this is fixed.

When tested in plunker Sample using the latest @angular npmcdn I still get the same issue.

Formatted: Mar 31, 2004
Actual: Thu Apr 01 2004 00:00:00 GMT-0400 (Eastern Daylight Time) 

Formatted: Apr 1, 2016
Actual: Fri Apr 01 2016 00:00:00 GMT-0400 (Eastern Daylight Time) 

Note, this is with EST. And seems to happen with some leap years.
If I change my PC's timezone to London time, it works as expected.

Formatted: Apr 1, 2004
Actual: Thu Apr 01 2004 00:00:00 GMT+0100 (GMT Daylight Time) 

Formatted: Apr 1, 2016
Actual: Fri Apr 01 2016 00:00:00 GMT+0100 (GMT Daylight Time) 

@vicb vicb reopened this Jun 22, 2016
@cperez87
Copy link
Author

Here is a jsFiddle Sample using the same April 1, 2004 with Moment.js. It formats correctly with that one (on EST)

@pkozlowski-opensource
Copy link
Member

Here is a plunker with the latest ng version: https://plnkr.co/edit/uPUgWaDUuu2ccKkYz8yl?p=preview

Could anyone within the EST time zone confirm that this is still an issue?

@cperez87
Copy link
Author

Yes, still a problem with EST.

Formatted: Mar 31, 2004
Actual: Thu Apr 01 2004 00:00:00 GMT-0400 (Eastern Daylight Time) 

Formatted: Apr 1, 2016
Actual: Fri Apr 01 2016 00:00:00 GMT-0400 (Eastern Daylight Time) 

Alternate with 1 extra hour
Formatted: Apr 1, 2004
Actual: Thu Apr 01 2004 01:00:00 GMT-0400 (Eastern Daylight Time)

@astrobob
Copy link

astrobob commented Dec 14, 2016

I have a problem with CEST too:
Formatted: 3 août 1955
Actual: Thu Aug 04 1955 00:00:00 GMT+0200 (CEST)

@pkozlowski-opensource
Copy link
Member

@astrobob thnx for this reproduce, I was able to confirm in one version of Chrome (54.0.2840.14) in CEST (France):

  • new Intl.DateTimeFormat('fr').format(new Date(1969, 9, 4)) gives "03/10/1969"
  • new Intl.DateTimeFormat('fr').format(new Date(1970, 9, 4)) gives "04/10/1970"

So just changing a year gives you 2 different days in the output. I've tested also with FFox and gives correct answers for both cases "04/10/1969" and "04/10/1969".

I need to test with more browsers and their versions but for now it looks like a bug in at least one version of Chrome (to be confirmed).

@pkozlowski-opensource
Copy link
Member

So, just re-tested with some more browsers and for new Intl.DateTimeFormat('fr').format(new Date(1969, 9, 4)):

  • Chrome 57.0.2951.0 (Official Build) canary gives "03/10/1969" (KO)
  • FFox 50.1.0 gives "04/10/1969" (OK)

Given the above I would expect it to be a bug in Chrome and as such I've reported it here: https://bugs.chromium.org/p/v8/issues/detail?id=5747

@TobiasKrogh
Copy link

@pkozlowski-opensource just stumbled upon this issue and fiddled around with it... while I can confirm your observations for new Date(1969, 9, 4) using new Intl.DateTimeFormat('fr').format(new Date(1968, 9, 4)) (one year earlier) the results are similar in Chrome and Firefox:

  • Chrome 56.0.2924.87 gives "03/10/1968" (KO)
  • Firefox 51.0.1 gives "03/10/1968" (KO)

@natebunney
Copy link

Maybe I am ignorant here but, if I am asking for a date to be formatted, why is it trying to adjust for time zone? It seems to me that formatting and adjusting for time zone are really two different things and should be handled separately, why does the time zone even matter to this pipe? All I expect is to get the same date out that I put in, every time.

@ocombe
Copy link
Contributor

ocombe commented Mar 13, 2017

The date pipe uses intl to format date and is part of the i18n package that Angular offers, that's why it uses locale dates.

@theHellyar
Copy link

This is an issue for me as well...anyone have a work around for now?

@cperez87
Copy link
Author

Seems to be related to Daylight Saving Changes before 2007.

This example shows all the dates that format inconsistently (based on US format) for a 10 year period starting Oct 1, 1999.
plunker sample

@cperez87
Copy link
Author

@theHellyar
You can use Angular2-Moment to display your Dates. It seems to work correctly.

Here is a Sample

@cimframe
Copy link

cimframe commented Jul 28, 2017

OK. This is driving me nuts.

I am using Angular 4 (^4.0.0 in package.json) and am not getting correct times...

I set a date as follows:

new Date("1988-11-05T14:00:00-07:00")

and am using the date pipe to format the outout as follows:

{{contact.lastModifiedDate | date:"EEEE, MMM dd, yyyy, hh:mm a"}}

I get the following for output:
Saturday, Nov 05, 1988, 01:00 PM

The last time I checked 14:00 should be 02:00 PM

I am using Chrome as my browser. And, by the way, the same output in Edge shows as:
Saturday, Nov 05, 1988, 01:11/5/1988 1:00:00 PM PM
Why is the date showing up in the time format?? and PM PM???

Is this a bug or a warp in time??

Some further observations...

I have used several different date strings in my calls to new Date("string") to no avail. When I use the date new Date("1957-08-08 14:30") it correctly shows as 02:30 PM
Thursday, Aug 08, 1957, 02:30 PM

This is what is driving me nuts...

@ocombe
Copy link
Contributor

ocombe commented Jul 28, 2017

We are completely rewriting the date pipe for angular v5, hopefully this should fix those kind of issues

@jmcclanahan
Copy link

I'd also like to add that I'm seeing a similar issue. I'm using the date pipe like so:
{{effectiveDate | date:"MM/dd/yyyy"}}
and I'm giving the pipe a unix timestamp, for example of 1456725600000.

This works fine in the timezone of the server (my timezone - CST), but anyone with a timezone to the west of my timezone will see the previous day. For example, if I give the date pipe 08/21/2017 I will see 08/21/2017, but anyone viewing my app on the west coast will see the previous day of 08/20/2017 which is not correct. This is causing me lots of calls from customers as this app is used by thousands of people a day.

@ocombe
Copy link
Contributor

ocombe commented Aug 21, 2017 via email

@jmcclanahan
Copy link

thanks @ocombe . Is the new date pipe in the 5.0 beta?

@ocombe
Copy link
Contributor

ocombe commented Aug 21, 2017 via email

@burnzoire
Copy link

Why not fix it in 4 as well?

@ocombe
Copy link
Contributor

ocombe commented Oct 5, 2017

Because in 4.x we defer those type of formatting to the intl api, and we don't have any control over it. To fix that we had to do a breaking change, that's why it is only available in 5.x unfortunately

@omaracrystal
Copy link

@ocombe Where can we find the solution to timezone?

@ocombe
Copy link
Contributor

ocombe commented Jun 28, 2019

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: common Issues related to APIs in the @angular/common package area: i18n freq2: medium type: bug/fix
Projects
None yet
Development

No branches or pull requests