Skip to content

DateTime type represented differently on fetch vs upsert #156

@ikromin

Description

@ikromin

Hi, I've been using PHP-GDS to build a small e-commerce site and ran into a minor issue with the DateTime data type. It appears that after an upsert() the field defined as Datetime in the schema is not converted to the same representation as when the entity is fetched.

For my entity schema, I define a Datetime field like this:

addDatetime('date',        true)

I then set my 'date' field to the PHP DateTime object like this:

$entity->date = new \DateTime('now', new \DateTimeZone('UTC'));

After I call upsert() and immediately do a var_export() on the entity, I can see the 'date' field is looking like this:

'date' => 
    DateTime::__set_state(array(
       'date' => '2017-06-12 10:29:13.000000',
       'timezone_type' => 3,
       'timezone' => 'UTC',
    ))

However, when I fetchById() or any fetch*() of the same object, var_export() gives me this:

'date' => '2017-06-12 10:29:13'

This behaviour is inconsistent. My current workaround it to do a fetchById() of my entity after upsert() however that seems a little inefficient. I could just check for the DateTime instance on the entity and set the field to just the date string, but that would make my entity handling code a little messy. Any suggestions?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions