Problem/Motivation
Much of the logic in system_time_zones() is outdated, as PHP now has the native ability to only return current timezones. While we're modernizing this logic, it makes sense to deprecate and remove (in Drupal 9) the old function.
Proposed resolution
Switch from using a regex to filter out old formats, and simply use \DateTimeZone::listIdentifiers(). At the same time, mark the old function deprecated and move this logic to Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsList. Note, since this relies on Drupal\Core\StringTranslation\TranslatableMarkup, it can't go into a component such as DateTimePlus.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3020455
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3020455-deprecate-systemtimezones-and
changes, plain diff MR !2966
Comments
Comment #2
jhedstromComment #3
jhedstromSomething like this. Note this is technically in the system module, but since it moves it to core's datetime, I'm leaving it under the datetime.module for visibility.
Comment #4
jhedstromComment #5
alexpottLet's take the opportunity to make this the boolean that it is.
Let's not use t() we can use TranslatableMarkup objects.
Let's call the new code here. So there are not two codebases. Also makes the lack of a deprecation test ok because we have no logic in this function then. It can cast the first param to a boolean.
Comment #6
alexpottI think moving
system_time_zones()toDateHelperseems a bit odd. The docs for that class are:This method doesn't fit into that. How about introducing a
TimeZoneHelper?This needs to be a change record not an issue node ID
Comment #7
jhedstromGood finds! I think this addresses #5 and #6.
Comment #8
jhedstromOops, I forgot to change some
NULLvalues to booleans with the corresponding docblock change.Comment #9
alexpottComment #10
mpdonadioNit, extra space.
It looks like the filtering is gone from TimeZoneHelper::getList() , and that this was essentially an unnecessary call since the goofy stuff is all in backzone now, and
Since we are touch this, this comment is wrong. The function doesn't do anything with "their local time & date".
I'm wondering if is should read like
"Generate an array of time zones names.
This method retrieves the list of IANA time zones names that PHP is configured to use, for display to users. It does not return the backward compatible names (i.e., the ones defined in the backzone file)."
I'm also wondering if we should add a third parameter to allow people to get the ALL_BC list. This periodically comes up in issues.
Comment #12
jhedstromThis should address #10 I think.
Comment #13
kim.pepperSmall nitpick:
Needs (optional) prefix.
Comment #14
kim.pepperOne more thing...
Needs to be 8.8.0 and format as per https://www.drupal.org/project/coding_standards/issues/3024461
Comment #15
jhedstromThis should address #13 and #14.
Comment #16
artis commentedRather than adding a limited parameter only for ALL_BC, why not add $what = \DateTimeZone::ALL and $country = NULL as default parameters to the method so that any list that can be provided by \DateTimeZone::listIdentifiers() can be provided by this method?
Comment #17
kim.pepperHaving another look at this issue...
Not a big fan of boolean flags for DX. I'd prefer explicit wrapper methods like getGrouped() getWithBc() or something like that. Thoughts?
Comment #18
kim.pepperReconsidered my feedback in #17 and I think it's ok the way it is.
Marking as RTBC as this is a straight re-roll.
Comment #19
alexpottI wonder if we should consider ditching the $blank functionality here.
I guess this is the bit that makes it useful... still it feels odd to be putting form considerations in this list. But then again it only really exists for forms. I think this is more of a TimeZoneFormHelper than a generic helper.
Why are we providing this option? It's not needed - and adds things to translate that never will be. I'm not convinced we should add this until necessary. The old function removed all of the BC timezones so not providing them is not a regression.
See this is weird because we creating a load of TranslatableMarkup for no reason. This could be
return \DateTimeZone::listIdentifiers();. I think the docs for the helper needs to point out that all the keys are valid timezone identifiers provided by\DateTimeZone::listIdentifiers().Comment #20
kim.pepper\Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsList()which I think makes more sense\DateTimeZone::listIdentifiers(). Couldn't find any other instances.Comment #21
alexpottor \DateTimeZone::listIdentifiers() instead- I think the CR should tell people to use the builtin when only using the machine value. Also need to update the class name.Could do with a legacy test.
Comment #22
mpdonadioThe BC list is really for systems where an old name is baked into existing config from a time when it was a valid name. They are not supposed to be used human facing.
Other than a little polish, looks good.
Comment #23
alexpottYeah but
This wasn't returning BC timezones anyway - right? So why do we need to add support for them? If you have them to deal with you need to write custom code atm - right?
Comment #24
alexpottThe preg_match() has been doing absolutely nothing since PHP5.3 :D - see https://3v4l.org/nYJ2R
Comment #25
mpdonadio#23, sorry for not being clear. That was support your comment about not needing the BC flag. The backward/links discussion comes up every month or two on the TZ mailing list. The official docs more or less say don't use them directly anymore for new config: https://github.com/eggert/tz/blob/master/theory.html#L298 (search for "backward" not "backzone").
#24, yeah, did the same thing. I suspect I also checked this at #10 and there is a fiddle out there, lost for the ages.
Comment #26
kim.pepperRe: #21
Comment #27
kim.pepperCreated follow-up #3083441: Deprecate system_user_timezone()
Comment #28
kim.pepperComment #30
avpadernoComment #31
mpdonadio#26 doesn't apply to 8.9.x. Re-rolling.
Comment #32
mpdonadioMinor merge conflict in the use section.
Comment #39
mile23Patch no longer applies.
Comment #43
spokje- Updated CR
- Rerolled latest patch in MR
Comment #44
bhanu951 commented@Spokje : Seems we were working simultaneously on this issue. Do Continue, I will pick another issue.
Comment #45
spokjeThanks @Bhanu951, I wasn't aware you're working on it as well. Next time assign the issue to yourself, like I did, so I know somebody is already working on it.
Comment #46
spokjeComment #47
kim.pepperRTBC+1 I worked on this issue too much to RTBC it myself.
Comment #48
spokjeHiding old patch files to show that the MR is where the party is at.
Comment #49
smustgrave commentedThis doesn't seem to be in the MR
Left a small nit picky thing in the MR too.
Comment #50
kim.pepperRebased on 10.1.x
Comment #51
smustgrave commentedCan the proposed solution be updated? Talks about moving to DateHelper but I don't see that?
Comment #52
kim.pepperUpdated IS to refer to
Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsListComment #53
smustgrave commentedThank you with sticking with me on this one. Everything looks good to me.
Comment #55
catchCommitted/pushed to 10.1.x, thanks! I'll open the follow-up and link it from here.
Comment #56
catchComment #57
catchHere's the follow-up #3343755: Simplify TimeZoneFormHelper.
Comment #60
liquidcms commentedHow is this list overridden?
With the old system_time_zones() function i hacked in a patch to add an alter (which i could then use to alter the list). I assumed if this was being redone the ability to alter the list would be included; but i don't see it here. Am i correct that this class can not be overridden?
Comment #61
kim.pepper@liquidcms I suggest you create a new issue to add this feature.