Skip to content

[couchbase] iOS date problems #211

Description

@PeterStaev

I'm experiencing some strange problems with dates being saved/loaded in the DB as null values. It is very random. So far it is happening for different locales, different time zones. Sometimes in a single object that has 2 fields with dates - one might get it right and the other one get as null. I'm not able to determine any pattern.

Looking at the code seems you are using NSDateFormatter to serialize dates using their JS .toISOString(). Reading through some best practices, seems when you want a fixed format it is best you also set the local to en_US_POSIX to avoid problems:
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW7

Also for iOS10+ it is recommended to use the newly introduced NSISO8601DateFormatter
https://developer.apple.com/documentation/foundation/nsdateformatter#2528261
https://developer.apple.com/documentation/foundation/nsiso8601dateformatter

What do you think to tweak the logic and use either ot those?

Also is there any reason why you have made the format use the Z timezone pattern, instead of the char Z. So you have

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

instead of

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

Here is an example of how the string format looks like with either of those: https://swiftfiddle.com/?c=H4sIAAAAAAAAA6tWSlayUsrMLcgvKlFwyy%2FNS0ksyczPiwHCnNQShQoFWwWXxJJUt%2Fyi3MSSktQiDU2QVIVeClwQqCJGqRIIdH19dVNS1EPUPTyscnOtiov1goODo2KUYvIKijLzSjQq9IpLgIx0jbSi%2FFwrsLF6efnlmiSaqB6lToSZSjpKZUCPmekZ6Bkp1QIAEfFcXeYAAAA%3D

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions