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

fix Views field custom date field output for year only #439

Merged

Conversation

jackrabbithanna
Copy link
Collaborator

Port and tweak of contributed PR #435

Before

Year only custom date fields for some time zones displays wrong value.

After

Custom fields with year only format always show correctly.

@civibot civibot bot added the 4.0.x label Aug 7, 2023
@jackrabbithanna
Copy link
Collaborator Author

Difference between this and contributed PR for 3.x branch is to always use date_default_timezone_get() and not the system-wide timezone configuration value

*/
public function convertToUtc(FieldDefinitionInterface $definition, $date_value) {
$datetime_format = $definition->getSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE ? DateTimeItemInterface::DATE_STORAGE_FORMAT : DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
$default_timezone = date_default_timezone_get();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the difference from PR #435 for the 3.x branch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using the global configuration then if the per-user timezone setting is allowed, and if the user chooses a different timezone, then could have a discrepancy. Drupal manages this and gives the "right" timezone returned by date_default_timezone_get();

@jitendrapurohit
Copy link
Collaborator

We've applied this PR on production and can confirm this is working for year-only custom fields.

@jackrabbithanna jackrabbithanna merged commit 28bc26e into eileenmcnaughton:4.0.x Feb 16, 2024
1 check passed
puresyntax71 added a commit to puresyntax71/civicrm_entity that referenced this pull request Apr 19, 2024
* 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)
puresyntax71 added a commit to puresyntax71/civicrm_entity that referenced this pull request Apr 27, 2024
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants