Discussion:
Handling dates with timezones
Brendan Duddridge
2018-03-11 04:58:34 UTC
Permalink
Hi,

In CouchbaseLite I've been using [CBLJSON dateWithJSONObject:] and [CBLJSON
JSONObjectWithDate:] to retrieve and store date information.

The date in the database looks like this in UTC:

{

date = "2018-01-12T07:00:00.000Z";

}

But I'd like to store the time zone information now along with the date.

When I use the time zone variant of [CBLJSON JSONObjectWithDate:timezone:]
this is what I get:
{

date = "2018-01-12T00:00:00.000-07:00";
}

So the time zone offset is now added to the time stamp.

I'm assuming that dateWithJSONObject can interpret both formats.

But I'm thinking maybe rather than using the time zone API variant to
generate the date value to store in the database, I should continue using
the UTC version and then store the time zone name (e.g. "America/Edmonton")
separately. This way I take offsets and DST out of the equation and let the
OS figure that out for me by creating my own NSTimeZone for the given time
zone name. Then I can use that to display the time to the user in that time
zone.

What do you think? Is it better to use JSONObjectWithDate or
JSONObjectWithDate:timezone?

Thanks,

Brendan
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchbase+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/85bf8ced-e370-4b83-a2ca-d6d4d3d87e5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jens Alfke
2018-03-12 18:57:59 UTC
Permalink
What do you think? Is it better to use JSONObjectWithDate or JSONObjectWithDate:timezone?
I've heard arguments for either behavior (not specific to a single API.)

A time zone name does convey more information than a GMT offset. If you're showing it to the user, "PST" or "USA Pacific" is a lot more meaningful than "GMT – 8:00".

—Jens
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchbase+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/4F2E35B0-F91F-4BA1-B702-287984F323F1%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...