-
Notifications
You must be signed in to change notification settings - Fork 64
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
Update default timezone handling for dates in CiviEntityStorage.php #461
Update default timezone handling for dates in CiviEntityStorage.php #461
Conversation
This fix makes alot of sense. We'll be testing internally and likely to merge soon. |
I reran the test in a separate PR, and then on my local .. there is a test fail.
|
The test: https://github.com/eileenmcnaughton/civicrm_entity/blob/4.0.x/tests/src/Kernel/CivicrmStorageGetTest.php#L65 Has the test been wrong all this time? |
With #472 and with this PR I get passing tests against Drupal 10.2.5 and CiviCRM 5.69 on local:
Tests in #471 pass, I'll close that one and merge this one. |
* origin/4.0.x: 4.0.x field mappings (eileenmcnaughton#430) Adding a raw value function to return value from values array (eileenmcnaughton#465) Add filter for state province. (eileenmcnaughton#453) Update default timezone handling for dates in CiviEntityStorage.php (eileenmcnaughton#461) fix testLoadContact birthdate assertion (eileenmcnaughton#472) port to 4.0.x from 436: Include dblocale table names in list of civicrm entity info (eileenmcnaughton#438) Ignore convert to UTC if custom field is date only (eileenmcnaughton#469) update contact entity referece field on contact merge (eileenmcnaughton#456) update test versions of Drupal 10.2 and CiviCRM 5.69 (eileenmcnaughton#468) Clean value on custom field for Float (Number) and Money field type (eileenmcnaughton#463) From eileenmcnaughton#378 for 4.0.x (eileenmcnaughton#466) Add reset to the file URLs generated. (eileenmcnaughton#458) fix Views field custom date field output for year only (eileenmcnaughton#439)
* origin/4.0.x: (41 commits) patch from issue 3420771 (eileenmcnaughton#475) only check for data in enabled components on module uninstall (eileenmcnaughton#476) Adds is Empty/NULL operators (eileenmcnaughton#423) Pathauto (eileenmcnaughton#470) fix test to use string instead of integer for zip code (eileenmcnaughton#474) 4.0.x field mappings (eileenmcnaughton#430) Adding a raw value function to return value from values array (eileenmcnaughton#465) Add filter for state province. (eileenmcnaughton#453) Update default timezone handling for dates in CiviEntityStorage.php (eileenmcnaughton#461) fix testLoadContact birthdate assertion (eileenmcnaughton#472) port to 4.0.x from 436: Include dblocale table names in list of civicrm entity info (eileenmcnaughton#438) Ignore convert to UTC if custom field is date only (eileenmcnaughton#469) update contact entity referece field on contact merge (eileenmcnaughton#456) update test versions of Drupal 10.2 and CiviCRM 5.69 (eileenmcnaughton#468) Clean value on custom field for Float (Number) and Money field type (eileenmcnaughton#463) From eileenmcnaughton#378 for 4.0.x (eileenmcnaughton#466) Add reset to the file URLs generated. (eileenmcnaughton#458) fix Views field custom date field output for year only (eileenmcnaughton#439) update Add Contact to Group Views Bulk operations action plugin access handler (eileenmcnaughton#464) Readme update (eileenmcnaughton#457) ...
* origin/4.0.x: patch from issue 3420771 (eileenmcnaughton#475) only check for data in enabled components on module uninstall (eileenmcnaughton#476) Adds is Empty/NULL operators (eileenmcnaughton#423) Pathauto (eileenmcnaughton#470) fix test to use string instead of integer for zip code (eileenmcnaughton#474) 4.0.x field mappings (eileenmcnaughton#430) Adding a raw value function to return value from values array (eileenmcnaughton#465) Add filter for state province. (eileenmcnaughton#453) Update default timezone handling for dates in CiviEntityStorage.php (eileenmcnaughton#461) fix testLoadContact birthdate assertion (eileenmcnaughton#472) port to 4.0.x from 436: Include dblocale table names in list of civicrm entity info (eileenmcnaughton#438)
Overview
When handling date values, always use the
DateTimeItemInterface::STORAGE_TIMEZONE
when converting the data.Before
When a view is taking a
![image](https://private-user-images.githubusercontent.com/569924/293583627-540fcd9a-e387-4279-9e9d-e8330cf799a3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk4MTAzMTAsIm5iZiI6MTczOTgxMDAxMCwicGF0aCI6Ii81Njk5MjQvMjkzNTgzNjI3LTU0MGZjZDlhLWUzODctNDI3OS05ZTlkLWU4MzMwY2Y3OTlhMy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxN1QxNjMzMzBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02OGVhMmE4MmY1NThlMTY3ZGRiNTg1ODU4OWZhOTlmZjU4MTI0MzM0YjJjNGY4MmUxODEyNTNhNjRmM2Q3ZDM0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.KEKpDfdP4F59IaTGO7y2f1vzh9r2ZFfaa5A2Gp1n4pc)
date
field from a CIVICRM entity, it uses the site's default timezone when setting the value to be displayed. Given that this is a date field, it does not have a timezone.After
We check to see if this is a date field or a datetime field. if it is a date field, use
DateTimeItemInterface::STORAGE_TIMEZONE
to ensure we don't accidentally change the date in the process.Technical Details
The
DateTimeItemInterface::STORAGE_TIMEZONE
assumes that all datetime data is stored in UTC, so we must also ensure our default timezone is UTC when dealing with date fields.Comments
I note that Drupal still shows a time of
12:00
no matter what, but that can be handled via formatting.