thekid/rfc — Issue #167: RFC 0167: RDBMS and Timezones
Author: thekid
Created: 2011-10-09 15:32:29+00:00
State: open

Scope of Change
====
Extend DBConnections to manage and handle timezones

Rationale
====
Provide a valid timezone for date objects created from database values instead
of using the default timezone.

Functionality
====
The DBConnection class will handle an optional parameter "timezone" in the DSN
of a database. All retrieved date objects will be created in this timezone.

Selecting data
----
Date objects will not be moved in the current timezone of the client but remain
in the configured timezone:

```php
query('select lastchange from test')->next('lastchange'));
?>
```

Would return: "2008-05-15 14:28:00+0000" including the timezone set in the DSN.

Inserting data
----
Date objects will be converted in the rdbms' timezone configured in the DSN
before being inserted:

```php
query('insert into test values (%s), $date');
?>
```

Will end up as:

```
+---------------------+
| lastchange |
+---------------------+
| 2008-05-15 14:56:40 |
+---------------------+

```

Backwards compatibility
----
When no timezone is configured the current behaviour will be used. Thus there
is no bc break necessary.

Security considerations
====
n/a

Speed impact
====
n/a

Dependencies
====
n/a

Related documents
====
* [http://xp-framework.net/rfc/contrib/rfc0167.diff patch against skeleton]
* [http://www.sybase.com/detail?id=1048699 sybase info about timezones and daylight saving times]

Comments
====
gellweiler, Thu May 15 17:16:31 CEST 2008
----
Should there be an option to auto detect the timezone of a
database? Mysql provides options to autoconvert datetimes and timestamps
into the clients timezone which would be an alternative to the current patch.
Unfortunately sybase databases don't have any support for timezone handling
other than a function called "getutcdate()" which could be used to calculate
the timezone offset for getdate().

friebe, Sat Mar 21 15:54:04 2009
----
I'm unsure whether this line:

```php
tz= $tz ? $tz : new TimeZone(date_default_timezone_get());
?>
```
...is needed inside ResultSet's constructor. Other than that, this
looks fine.