dg / dibi

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

DATE != DATE TIME #123

Closed okias closed 10 years ago

okias commented 10 years ago

Problem: before bug, DATE is represented as YYYY-MM-DD, after bug YYYY-MM-DD HH:MM:DD

Bisected to this (because some errors, I couldn't bisect to final commit)

9bc53109a06bc80861ea56f2544ce871919af962 maybe 3288b38b6c1788d910c4e0652833455e489b444c NO a8672bb6ff9c5e43d4717dc7c70faaeef10aea61 NO 2a5934c385c575636b43d7860d6234581b83aff1 NO 8c8b3c3dc1f8148898d962275f086eae0fbf14a6 guess NO 2c1950eacf1ff2f6131f2e0065cb939f42a38552 maybe touching DATE 4c85d1d55c7cf52c97097448334601f7b6a81ac5 NO 8c481bc1283f57578996b1cfde97c3ad8f0aeb95 maybe baf08d3c71d7717f042ef5e2b0d5081279631eef maybe? a8f5e09b6999a6fdb45dd25be0a90e3f96946238 guess not

REVISION eee105f607e4c80b2f53cbf08959a70e37e6b98c works, 9a605573a2916d3c5b1ffe95a4ba605889b998a9 is broken.

milo commented 10 years ago

And bug is actually what? Could you provide a code snippet and show what is wrong?

okias commented 10 years ago

in database is saved DATE as type "date" (example 2013-05-01). In nette (dibi), is loaded as DATETIME (always with 00:00:00 included at end, so example: 2013-05-01 00:00:00)

EDIT: code example could be any select on date field from database (it's wrongly returned as datetime into gridito, forms, everywhere..)

This is correct output before these commits: weston2 after these commits: weston2

milo commented 10 years ago

You can set default format in config:

'driver' => 'postgre',
'host' => 'localhost',
...
'result' => array(
    'formatDate' => 'd.m.Y',
    'formatDateTime' => 'U',
),
milo commented 10 years ago

And you can set it manually for every query:

$dibi->query('SELECT ...')->setFormat(dibi::DATE, 'd.m.Y')->fetchAll()
okias commented 10 years ago

Thank you milo, I used default format solution and it work fine.

Anyway I think, default behaviour for formatDate should be Y-m-d, as before without 00:00:00 at end.

milo commented 10 years ago

The problem is deeper. Datatype autodetection converts all date and time values to DibiDateTime which extends PHP's DateTime. So all these values are objects. Default converting by __toString is Y-m-d H:i:s, that's why you see that. You would have to have class for every time type. Like DibiTime, DibiDateTime, DibiDate, DibiDateTimeWithTimezone, DibiInterval... Things would come complicated.