You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Safari only] Invalid argument for pipe 'DatePipe' - Safari cannot parse Date offsets #12334
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Error shows up, only on Safari(Version 10.0 (11602.1.50.0.10))
Expected behavior
Expected no error to show up. Google Chrome works fine
Minimal reproduction of the problem with instructions
Go to the following Plunkr with Safari and Google Chrome. Chrome works perfectly.
Reacted by AndreasGassmann, Sampath Lokuge, lsholubka, Aleksandar Djindjic, Ivan Koretskyy, Gaurav Gangopadhyay, David Sandoz, EverNavarro, Silviu Stroe, Alvaro Martinez and 1 more
changed the title [-]Invalid argument '2016-01-20T19:00:00+0000' for pipe 'DatePipe'[/-][+]Invalid argument for pipe 'DatePipe' [Safari only] Safari cannot parse Date offsets[/+]on Oct 17, 2016
changed the title [-]Invalid argument for pipe 'DatePipe' [Safari only] Safari cannot parse Date offsets[/-][+][Safari only] Invalid argument for pipe 'DatePipe' - Safari cannot parse Date offsets[/+]on Oct 17, 2016
It's still a bug in safari when you have date like that: 2017-11-02 00:00:00.000
edit: '2017-11-02 00:00:00.000'.replace(/\s/g, "T") this work's in Safari and Chrome.
Reacted by Abhishek Jain, Torben, Mohammad Irfan, Dmitry Belov, Arthur Mudrick, Thiago Elias, Warren Gutierrez, javier, raman0619, Kevin González and 1 more
I ended up using a getDate() function that I run once when I get a response from my API, which proves me with a new Date-object that is compatible.
This code makes certain assumptions, so you should modify it to your needs. (additional null check / change input parameter type)
protected getDate(value: any): Date {
// https://github.com/angular/angular/issues/12334
return value ? new Date(value.date.replace(/\s/g, 'T')) : undefined;
}
This is a very subtle bug that is not easy to find, hope for progress on this one.
Perhaps a new issue should be opened as this bug is not about / or - but dates such as 2017-11-02 00:00:00 if i recall correctly.
Activity
vicb commentedon Oct 17, 2016
Please provide the repro as a plunker and make sure the issue is not already reported.
dolanmiu commentedon Oct 17, 2016
https://plnkr.co/edit/8ieBbla6Pk3jFQKkHsNc?p=preview
Here is the Plunkr. I've updated the original post too
Try this on Google Chrome and then try this on Safari
Mac OS X El Capitan
dolanmiu commentedon Oct 17, 2016
I have found out the cause:
Both work in Google Chrome of course.
Here is the line in the
angularsource:https://github.com/angular/angular/blob/master/modules/%40angular/common/src/pipes/date_pipe.ts#L109
dolanmiu commentedon Oct 17, 2016
I have a strong feeling it is somewhat related to this:
http://stackoverflow.com/questions/6427204/date-parsing-in-javascript-is-different-between-safari-and-chrome
pushtell/react-bootstrap-date-picker#2
[-]Invalid argument '2016-01-20T19:00:00+0000' for pipe 'DatePipe'[/-][+]Invalid argument for pipe 'DatePipe' [Safari only] Safari cannot parse Date offsets[/+][-]Invalid argument for pipe 'DatePipe' [Safari only] Safari cannot parse Date offsets[/-][+][Safari only] Invalid argument for pipe 'DatePipe' - Safari cannot parse Date offsets[/+]hypery2k commentedon Jan 12, 2017
any plans to fix this?
4 remaining items
fix(common): DatePipe parses input string if it's not a valid date in…
jburtondev commentedon Jul 3, 2017
This will work as a temporary solution. Of course, you can replace the replaced string value with what you require, e.g. hyphen instead of comma.
Then use it like this:
fix(common): DatePipe parses input string if it's not a valid date in…
fix(common): DatePipe parses input string if it's not a valid date in…
MichalCzerwonka commentedon Nov 2, 2017
It's still a bug in safari when you have date like that: 2017-11-02 00:00:00.000
edit:
'2017-11-02 00:00:00.000'.replace(/\s/g, "T")this work's in Safari and Chrome.abhishekdgeek commentedon Nov 8, 2017
Sadly this is still there for spaces. Easier if you are working with mongodb where date is stored in ISO 8601 format.
artuska commentedon Mar 1, 2018
@michaell94 well, event if i have
2017-11-02 00:00:00date i get an error:abhishekdgeek commentedon Mar 7, 2018
Yes, use following format - 2017-11-02T00:00:00Z
NOTE Z at the end, else you will have timezone issue in Safari and Chrome. :)
LeonardoMinatiCrispyBacon commentedon Jul 31, 2018
This issue is still here
sebastian-heinz commentedon Dec 18, 2018
I also run into this (angular 7.0)
renatop7 commentedon Apr 7, 2019
Any fix for this?
sebastian-heinz commentedon Apr 8, 2019
I ended up using a getDate() function that I run once when I get a response from my API, which proves me with a new Date-object that is compatible.
This code makes certain assumptions, so you should modify it to your needs. (additional null check / change input parameter type)
This is a very subtle bug that is not easy to find, hope for progress on this one.
Perhaps a new issue should be opened as this bug is not about
/or-but dates such as2017-11-02 00:00:00if i recall correctly.abhishekdgeek commentedon Apr 9, 2019
@sebastian-heinz take a note about Z present else you will mess up the timezone for safari.
angular-automatic-lock-bot commentedon Sep 14, 2019
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.