Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime type represented differently on fetch vs upsert #156

Open
ikromin opened this issue Jun 12, 2017 · 3 comments
Open

DateTime type represented differently on fetch vs upsert #156

ikromin opened this issue Jun 12, 2017 · 3 comments

Comments

@ikromin
Copy link

ikromin commented Jun 12, 2017

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?

@tomwalder
Copy link
Owner

Hi there. Sorry for the late reply.

This is a known (and undesired) behaviour of the library at present.

v4 will use DateTime in both directions.

@tomwalder
Copy link
Owner

I've pre-released v4-beta1 which contains this feature

https://github.com/tomwalder/php-gds/releases/tag/v4-beta1

@tomwalder tomwalder added this to the 4.0 DateTime support milestone Oct 5, 2017
@ikromin
Copy link
Author

ikromin commented Oct 5, 2017

Thanks, I'll try and find the time over the next couple of weeks to test it in my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants