Skip to content

NSDate fetch crash on some dates #302

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

Open
vmirgorod opened this issue Dec 22, 2015 · 3 comments
Open

NSDate fetch crash on some dates #302

vmirgorod opened this issue Dec 22, 2015 · 3 comments
Labels
Milestone

Comments

@vmirgorod
Copy link

Possible it is better to use optional there ...
2015-12-22 09 11 23

@jfbomber
Copy link

jfbomber commented Jun 1, 2016

I am running into this same problem.

@iNoles
Copy link

iNoles commented Jun 1, 2016

it can be possible, but somebody else have to redesign whole Value methods for it.

You could use custom DateFormatter to pass timeIntervalSince1970

@jberkel jberkel added this to the 0.11.2 milestone Dec 7, 2016
@jberkel jberkel modified the milestones: 0.11.2, 0.11.3 Dec 29, 2016
@jberkel jberkel modified the milestones: 0.11.3, 0.11.4 Mar 30, 2017
@MattGrdinic
Copy link

MattGrdinic commented Apr 28, 2017

I had the same issue and the fix, for me at least, was a bit subtle.

So I noticed the crash would happen despite stringValue being an acceptable date string. This didn't make sense. Why would it crash when given a perfectly acceptable date value? Turns out this insight was a big clue:

What was actually happening was dateFormatter was causing the problem. Specifically, dateFormatter was being given a different format than the passed in string a bit later in my code, as in:

dateFormatter.dateFormat = "MMM d, yyyy"

This new format would then be applied to the one in SQLite > Foundation.swift, which would, when I had a date with a different format get selected, cause the crash.

In other words I'd give it a string just like yours, but the formatter expected a string in my new format. The date conversion would fail and the optional unwrap would cause a crash.

The fix then, again, for me at least, was to simply set the proper format before the database column was accessed. For example:

dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"

..Access database column..

if let lastRefreshedValue = selectrow[_lastRefresh] {

etc...

Alternatively, we can search for an remove any calls to dateFormatter.dateFormat in our project.

@jberkel jberkel modified the milestones: 0.11.4, 0.12.0 Sep 30, 2017
@jberkel jberkel modified the milestones: 0.12.0, 0.13.1 Aug 23, 2021
@jberkel jberkel added the bug label Aug 25, 2021
@jberkel jberkel modified the milestones: 0.13.1, 0.13.2 Nov 17, 2021
@jberkel jberkel modified the milestones: 0.14.0, 0.14.1 Jul 17, 2022
@jberkel jberkel modified the milestones: 0.14.1, 0.15.0 May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants