Currently, Sequel doesn't really pay much attention to time zones.
When putting datetime values in the database, it generally omits the
time zone information.  When retrieving times, it just uses the parse
method of the datetime_class, so if the string doesn't include time
zone information, ruby will assume it is in local time.

It's not difficult to override just a few methods to make Sequel use
UTC everywhere, but it's probably something that Sequel should
support.  However, I don't plan on making UTC conversion the default,
as it would likely break applications.

There's basically two separate issues in regards to time zones with
Sequel:

1) Putting datetimes into the database:

This can be handled by modifying literal_datetime for the dataset
class.  The DateTime or Time object can be converted to UTC before
being literalized.

2) Getting datetimes out of the database:

This is adapter dependent.  In most cases, the underlying driver
handles type conversion, not Sequel.  However, for the most common
adapters (postgres, mysql, and sqlite), Sequel handles the
conversion.  In the cases where Sequel does not handle the conversion,
there's not much we can do.  If Sequel does handle the conversion, it
generally passes the string to Sequel.string_to_datetime.  In or
around there, after the string is parsed into an object, the object
can be converted to UTC.

Unfortunately, there are some problems involved.  If you set Sequel to
convert times to UTC, and the database returns a time with no time
zone information, there's no way for Sequel to know if the time is
already in UTC or if it needs to be converted to UTC.  This is the
reason converting to UTC will not be the default.

Anyway, I want to get some general thoughts on this before I decide
how to handle things.  I don't think it is a lot of work to get Sequel
to support UTC times, but I'd like to make sure it's simple for the
user to use while still handling things correctly (when configured
correctly, of course).

I'm thinking about this API:

# Converts datetimes to UTC on both input and output
Sequel.convert_datetimes = :utc # or :local

# Convert datetimes to UTC on input (going into the database)
Sequel.convert_input_datetimes  = :utc # or :local

# Convert datetimes to UTC on output (coming out of the database)
Sequel.convert_output_datetimes  = :utc # or :local

Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to