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 }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Date Filter: Safari throws error if the date is an Invalid Date. #13415
In my tests the date filter, on Safari, is returning a Date object correctly. It is just that this object represents an 'invalid' date.
It would seem to me that the problem is in our stringify function, which should catch the error thrown by JSON.stringify for invalid Date objects.
Travis seems to have failed on apt-get in build 115755797 for every test. All tests currently pass on my local build and I suspect this to be an issue with the build environment at that time. How should I go about rectifying this since there doesn't seem to be retry option?
Furthermore, in PR #14221 , @googlebot apparently found my CLA for the pull request, but not for my commits, even though both were performed on the same account. Is there a recommended way to rectify this issue as well? It could possibly be related to the fact that my email is hidden in GitHub. I'd prefer not to change that, but would if it is required.
I just updated to 1.4.12 and I still receive the RangeError: Invalid Date in Safari.
In my case I have an expression like: {{ mything.timestamp * 1000 | date:'medium' }} and the error is happening when mything.timestamp is undefined, so date filter ends up getting a NaN value as input.
This solution worked for me:
filters.js::591
if (isNumber(date)) {
date = new Date(date);
}
change to:
if (isNumber(date) && !isNaN(date)) {
date = new Date(date);
}
I was going to submit a PR for this, but then I found this issue was closed already so I just updated.
Should I go ahead with a PR to add the !isNaN check?
Hi, @plong0, that fix addresses only a subset of the problems with this issue, though still sounds like a useful feature to have. For more details on why it doesn't address everything, check out #14221. I'm not sure on what the exact procedure is on proceeding from here, I'll let the Angular team handle that. I suspect you'll want to open a new issue, but I cannot be certain.
I haven't made up my mind if this should be fixed or not. (It will be a breaking change and I am not sure the benefits are enough to justify it).
But you can sure go ahead a create a PR and kick off the discussion 😄
Hm, I never thought that it could be a breaking change - but now that you mention it, I can imagine how it could be.
In the mean time, I have a very simple workaround where I pass my date values through a timestamp filter before passing them to date filter. The timestamp filter is doing a simple check so the date filter will get either a valid timestamp integer (* 1000 if conversion is needed) or null if the input wouldn't convert to a valid date object.
Activity
petebacondarwin commentedon Dec 7, 2015
In my tests the date filter, on Safari, is returning a Date object correctly. It is just that this object represents an 'invalid' date.
It would seem to me that the problem is in our
stringifyfunction, which should catch the error thrown byJSON.stringifyfor invalid Date objects.petebacondarwin commentedon Dec 7, 2015
See http://plnkr.co/edit/IKr0VPSzs2Mh9ORV7iH1?p=preview
18 remaining items
BobChao87 commentedon Mar 19, 2016
I'm having some issues with the actual build.
Travis seems to have failed on
apt-getin build 115755797 for every test. All tests currently pass on my local build and I suspect this to be an issue with the build environment at that time. How should I go about rectifying this since there doesn't seem to be retry option?Furthermore, in PR #14221 , @googlebot apparently found my CLA for the pull request, but not for my commits, even though both were performed on the same account. Is there a recommended way to rectify this issue as well? It could possibly be related to the fact that my email is hidden in GitHub. I'd prefer not to change that, but would if it is required.
fix(toJson): correct serialization of invalid dates
docs(toJson): documented the Safari RangeError known issue
plong0 commentedon Aug 8, 2016
I just updated to 1.4.12 and I still receive the RangeError: Invalid Date in Safari.
In my case I have an expression like:
{{ mything.timestamp * 1000 | date:'medium' }}and the error is happening whenmything.timestampisundefined, so date filter ends up getting aNaNvalue as input.This solution worked for me:
filters.js::591
change to:
I was going to submit a PR for this, but then I found this issue was closed already so I just updated.
Should I go ahead with a PR to add the
!isNaNcheck?BobChao87 commentedon Aug 8, 2016
Hi, @plong0, that fix addresses only a subset of the problems with this issue, though still sounds like a useful feature to have. For more details on why it doesn't address everything, check out #14221. I'm not sure on what the exact procedure is on proceeding from here, I'll let the Angular team handle that. I suspect you'll want to open a new issue, but I cannot be certain.
gkalpak commentedon Aug 8, 2016
I haven't made up my mind if this should be fixed or not. (It will be a breaking change and I am not sure the benefits are enough to justify it).
But you can sure go ahead a create a PR and kick off the discussion 😄
plong0 commentedon Aug 9, 2016
Hm, I never thought that it could be a breaking change - but now that you mention it, I can imagine how it could be.
In the mean time, I have a very simple workaround where I pass my date values through a
timestampfilter before passing them todatefilter. The timestamp filter is doing a simple check so the date filter will get either a valid timestamp integer (* 1000 if conversion is needed) or null if the input wouldn't convert to a valid date object.docs(toJson): documented the Safari RangeError known issue