nextras / orm

Orm with clean object design, smart relationship loading and powerful collections.
https://nextras.org/orm
MIT License
310 stars 57 forks source link

DateTime - different times #173

Closed f3l1x closed 6 years ago

f3l1x commented 8 years ago
Current date: 19.4.2016
Current time: 12:00
PHP timezone: Europe/Prague
PHP time: 12:00
Server time: 12:00

Neon config:

dbal:
    connectionTz: auto

If entity has column DateTime $created with macro annotation {default now}. I found in database time 10:00.

If entity does not have an annotation {default now} and I set date manually via $e->created = new DateTime(). Time is correct.

How is that possible?


Does it make difference when I use pure \DateTime, Nette\Utils\DateTime or Nextras\Dbal\Utils\DateTime?

Thanks.

hrach commented 8 years ago

How is that possible?

imo it's not possible ;) failing testcase needed.

Does it make difference when I use pure

shouldn't.

f3l1x commented 8 years ago

I make more tests and {default now} depends on simpleStorageTz, because debugger goes over method convertDateTimeSimpleToSql.

SimpleStorageTz is by default configured to UTC.

Is it right behaviour?

By documentation:

simple storage time zone – is timezone for column types without automatic timezone conversion; this setting is introduced mainly for backward compatibility, if you migrate from another database abstraction layer, your column values are probably stored in different timezone.

But column $created is type DateTime.

hrach commented 8 years ago

what is your column type in db? You are mixing few things, default now does the same thing as new DateTime.

f3l1x commented 8 years ago

Column type in PostgreSQL is timestamp. But, in the preview is it showed as formatted date time, e.q. 2014-07-03 09:30:04.097605.

Any idea?

hrach commented 7 years ago

Did you solve this, or is it still an issue?

honzarac commented 7 years ago

Yes I have same problems. Orm save different times to database depends on timezone config. Often I must try different combinations of config.

On some servers works config SimpleStorageTz, but somewhere no.

hrach commented 7 years ago

@honzarac wich column type are you using and what is your orm configuration?

honzarac commented 7 years ago

For example on wedos

dbal:
    connectionTz: auto-offset # or '+02:00' result is the same
    driver: mysqli
    host: wm123.wedos.net
    database: ***
    username: ***
    password: ***

Column type is always date or datetime

From phpinfo() Default timezone Europe/Prague

in database 2017-04-15 18:56:22 on web 2017-04-15 20:56:22

hrach commented 7 years ago

@honzarac could you please debug what is returned here? https://github.com/nextras/orm/blob/5f64787e99d4ee82f56d758a80d412bf4d848afd/src/Mapper/Dbal/StorageReflection/StorageReflection.php#L301 e,g, what returns $this->platform->getColumns($this->storageName), there may be a problem with the above defined $types which camelcase :X

honzarac commented 7 years ago
last_action_time => array (8)
name => "last_action_time" (16)
type => "DATETIME" (8)
size => NULL
default => NULL
is_primary => FALSE
is_autoincrement => FALSE
is_unsigned => FALSE
is_nullable => TRUE

$types

array (1)
DATETIME => TRUE
hrach commented 6 years ago

The original @f3l1x issue is that he used a wrong type in db, timestamp doesn't have timezone handling. The same seems to be for @honzarac who uses datetime instead of timestamp.

Current version of Dbal & Orm has better support for this and it should not do such damage. Both guys, you should try it.

Please, also double check documentation how timezone works :) (works in current Dbal) https://nextras.org/dbal/docs/3.0/datetime