Handling dates with timezones

8 views
Skip to first unread message

Brendan Duddridge

unread,
Mar 10, 2018, 11:58:34 PM3/10/18
to Couchbase Mobile
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


Jens Alfke

unread,
Mar 12, 2018, 2:58:04 PM3/12/18
to Couchbase Mobile


> On Mar 10, 2018, at 8:58 PM, Brendan Duddridge <bren...@gmail.com> wrote:
>
> 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
Reply all
Reply to author
Forward
0 new messages