Problem/Motivation

With #2799987: Datetime and Datelist element's timezone handling is fragile, buggy and wrongly documented we improved and enforced timezone handling for Datetime and Datelist through the #date_timezone property. We should now make sure its documentation reflects the changes.

#3015647: $element['value']['#date_timezone'] is not a string fatal error. is an example of how #date_timezone has been (ab)used before, and after the new change a fatal error is raised due a string being expected rather than a \DateTimeZone object.

The current documentation for #date_timezone reads:

#date_timezone: The local timezone to use when displaying or interpreting dates. Defaults to the value returned by

Without specifying *a string* is expected.

Proposed resolution

Update the documentation.

Remaining tasks

  • Update the #date_timezone documentation, specifying a timezone name string is expected. Done by documenting this must be a TZID together with an example 'Asia/Kolkata'.
  • Understands if more documentation improvements are needed. Can't think of anything else. All changes from [ #2799987] have been covered.

User interface changes

Nope.

API changes

No, however change record https://www.drupal.org/node/2880055 doesn't specify a timezone name string is expected so although this change doesn't alter the API it does affect (aka clarify) its usage as well as its documentation.

Data model changes

No.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gambry created an issue. See original summary.

gambry’s picture

Issue summary: View changes

Fixing CR link.

gambry’s picture

Issue tags: +Novice
deepanker_bhalla’s picture

Status: Active » Needs review
FileSize
1.55 KB

Does it works?

msankhala’s picture

No @deepanker_bhalla this will not work. The documentation you modified does not make any sense. You simply added "Without specifying" string in #date_timezone property's documentation. This issue is about specifying that value of the #date_timezone property should be in string format.

Here is the new patch.

gambry’s picture

Status: Needs review » Needs work

I'm worried "in the format returned by date_default_timezone_get()" can confuse developers.

Why don't we use something like:
"The local timezone name string to use when displaying or interpreting dates, i.e. 'Asia/Kolkata'. Defaults to the value returned by drupal_get_user_timezone()." so we reduce the changes to minimum while stressing we need a timezone name string, providing also an example.

msankhala’s picture

I don't think this will confuse the developers because date_default_timezone_get() and drupal_get_user_timezone() both return string in the same format. Also, there is an example of what should be the format.

dpi’s picture

Instead of "time zone string", "string", "in format returned by date_default_timezone_get()" or similar, I recommended to use something similar to Time Zone Identifier (aka TZID) as defined by TZData / Olson Database.

W3 Working With Time Zones: https://www.w3.org/TR/timezone/#tzids

Also take care as time zone is two words.

gambry’s picture

Yep, agree with #8 as I believe using a PHP-agnostic naming convention it's better.

I suggested "timezone name [string]" (one word + name) because this is what the documentation for \DateTimeZone::__constructor() says.

So something like:

"The Time Zone Identifier (TZID) to use when displaying or interpreting dates, i.e. 'Asia/Kolkata'. Defaults to the value returned by drupal_get_user_timezone()."

?

msankhala’s picture

Yes I agree with @dpi in #8. @dpi Are you suggesting to use "time zone" instead of "timezone"? But everywhere it is used as "timezone".

singhkiran’s picture

Assigned: Unassigned » singhkiran
Issue tags: -Novice +ContributionWeekend2019

I will work on this in @ContributionWeekend2019.

singhkiran’s picture

Assigned: singhkiran » Unassigned
Status: Needs work » Needs review
FileSize
2.68 KB

Please find above patch and review , i have added space in timezone. Thanks

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gambry’s picture

Status: Needs review » Needs work
Issue tags: +Novice

@singhkiran thanks a lot for your contribution. When updating previous patches is always superuseful to provide also an interdiff, so we can compare what's been changed. See here details about how to create an interdiff.

Setting this to needs work as we still need to changes the instances of "The string representation of time zone in the format returned by date_default_timezone_get(). For example: 'Asia/Kolkata'. This local timezone is used when displaying or interpreting dates. Defaults to the value returned by drupal_get_user_timezone()." to something like "The Time Zone Identifier (TZID) to use when displaying or interpreting dates, i.e. 'Asia/Kolkata'. Defaults to the value returned by drupal_get_user_timezone()."

vacho’s picture

I contribute to this refactoring the text to seems more like the current but adding the TZID concept.

gambry’s picture

Thank you @vacho ! We are nearly there. The comments span over the 80chars limit. Can you update those 4 lines?

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
FileSize
2.48 KB
1.95 KB

Updated the patch as per comment #16 & also added an interdiff.

Status: Needs review » Needs work

The last submitted patch, 18: 3016064-18.patch, failed testing. View results

gambry’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community

All looks good, thanks! Tests failure is not related (see #3055648: Frequent random fail in \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest). RTBCing.
Updating remaining tasks section on IS.

alexpott’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 1dc9a511fc to 8.8.x and 00ce4413ca to 8.7.x. Thanks!

  • alexpott committed 1dc9a51 on 8.8.x
    Issue #3016064 by yogeshmpawar, vacho, msankhala, singhkiran,...

  • alexpott committed 00ce441 on 8.7.x
    Issue #3016064 by yogeshmpawar, vacho, msankhala, singhkiran,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.