Datetimes and UTC

197 views
Skip to first unread message

Kenneth Hoffmann

unread,
Sep 30, 2013, 4:44:58 PM9/30/13
to ceq...@googlegroups.com
Right now it looks like timestamps auto-convert UTC times to local time with TZ info. Is there a way to circumvent this, short of doing something like overriding the data method to re-convert that field to UTC when it is read or written?

Matthew A. Brown

unread,
Sep 30, 2013, 6:06:40 PM9/30/13
to Kenneth Hoffmann, ceq...@googlegroups.com
Hi Kenneth,

Cassandra's internal representation of timestamps is simply milliseconds since epoch, so in terms of the actual data storage, timestamps are not in the picture. cassandra-cql casts Time objects to the appropriate millisecond value when preparing them for a CQL query:


Similarly, Time columns in result rows are cast using the inverse of that operation:


So the behavior you're observing is all at the cassandra-cql level. Since timestamps stored in Cassandra don't carry time zone information, it wouldn't be possible to retain the time zone of the Time object that gets stored, but it is probably worth having better across the board behavior, probably just using `in_time_zone`.

My instinct is that at the `Cequel::Metal` level, we should always convert timestamp values to UTC in result rows; and then in Cequel::Record, timestamp attributes should be converted to Time.zone (which I believe is UTC unless otherwise configured). Does that seem reasonable?

Mat


On Mon, Sep 30, 2013 at 4:44 PM, Kenneth Hoffmann <ken...@backupify.com> wrote:
Right now it looks like timestamps auto-convert UTC times to local time with TZ info. Is there a way to circumvent this, short of doing something like overriding the data method to re-convert that field to UTC when it is read or written?

--
You received this message because you are subscribed to the Google Groups "Cequel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cequel+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Kenneth Hoffmann

unread,
Oct 1, 2013, 11:19:22 AM10/1/13
to ceq...@googlegroups.com, Kenneth Hoffmann
I think so. Definitely on writing as UTC, and I guess on the reading if you want it as a different TZ you can override the data method to convert it to whichever works for you.

Matthew A. Brown

unread,
Oct 1, 2013, 11:35:48 AM10/1/13
to Kenneth Hoffmann, ceq...@googlegroups.com
Cool – I've created an issue: https://github.com/cequel/cequel/issues/46
Reply all
Reply to author
Forward
0 new messages