dg / dibi

Dibi - smart database abstraction layer
https://dibiphp.com
Other
487 stars 135 forks source link

DateTime's time zone should be normalized before saving #100

Open paranoiq opened 11 years ago

paranoiq commented 11 years ago

if a DateTime has different time zone, it shold be normalized to the time zone of server

there may be databases, which are capable of saving a datetime with timezone, so i am not sure yet, if the normalization shold occur in DibiFormater or in a Driver

(see also: https://github.com/nette/nette/issues/1168)

milo commented 11 years ago

What about %d and %t do the normalization, and modifiers %dz and %tz wouldn't, plus add timezone value.

Next point is, how to get the server timezone value. I don't use the MySQL, but afaik, value DEFAULT can be returned. From my point of view, normalization should be done only if configured (I mean in PHP application), or it should be setable on Connection.

paranoiq commented 11 years ago

@milo: i do no think we need a "yes pleas, shoot me in my leg" modifier

getting the timezone is the tricky part. timezone is set by Dibi on connection start, but a "+02:00" format is also enabled* and currently used as default if no timezone is given

*) allowing this could be considered as another bug, because setting offset in config file does not consider DST time shifts over the year. but it should be bacward compatible, i guess...

my current sollution for Dibi is here: https://gist.github.com/paranoiq/6021606

milo commented 11 years ago

i do no think we need a "yes pleas, shoot me in my leg" modifier

Your solution is good for DBs without timezoned type. But what about e.g. PostgreSQL? Imagine the query, where created column is capable to save the timezone:

$dibi->query('INSERT INTO tab (created) VALUES (%d)');

I think, instead of %d shoud be %dz explicitly used. I don't see any way how to do the detection.

Your kind of solution for DateTime normalization is good and it is not in conflict in proposed %dz and %tz modifiers.

allowing this could be considered as another bug

Agree. I parcipated in the discussion on Nette FW issue when it was removed.

paranoiq commented 11 years ago

you are right. i missunderstood your first comment. in that case the %dz/%tz makes sense. it should be driver specific and should throw an error on database which does not support it (or fallback to %d/%t?)

I parcipated in the discussion on Nette FW issue when it was removed.

what issue do you mean?