Right now system.module has duplicated code for producing the html to select
site timezone and user timezone, yet still doesn't make the functionality
available to other modules.
This patch collapses it to a single theme.
Actually the theme has two different styles, the existing one that shows
example times, and another style that uses labels that are the traditional
timezone acronym designators.

-mda

diff -r1.138 system.module
92,98c92,94
< $timestamp = time();
< $zonelist = array(-11, -10, -9.5, -9, -8, -7, -6, -5, -4, -3.5, -3, -2, -1, 0, 1, 2, 3, 3.5, 4, 5, 5.5, 5.75, 6, 6.5, 7, 8, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 14);
< foreach ($zonelist as $offset) {
< $zone = $offset * 3600;
< $zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone);
< }
< $data[t('Locale settings')] = form_select(t("Time zone"), "timezone", $edit["timezone"], $zones, t("Select what time you currently have and your time zone settings will be set appropriate."));
---
> // use the site default as the user default
> $sel_tz = $edit["timezone"] ? $edit["timezone"] : variable_get('date_default_timezone', 0);
> $data[t('Locale settings')] = theme('select_timezone', t("Time zone"), 'timezone', $sel_tz, t("Select what time you currently have and your time zone settings will be set appropriately."));
103a100,163
> /**
> Return html for selecting a timezone, with $timezone being the current value.
> If $timezone is NULL, it defaults to the user's timezone, or 0 if that isn't set either.
> */
>
> function theme_select_timezone($label, $var, $timezone = NULL, $help = '', $style = 'timed') {
> if ($timezone === NULL) {
> global $user;
> $timezone = $user && $user->timezone ? $user->timezone : 0;
> }
> $zones = $style == 'timed' ? _theme_timed_timezones() : _theme_labeled_timezones();
> return form_select($label, $var, $timezone, $zones, $help);
> }
>
> define(_TZ_SECS, 3600);
>
> /**
> Return timezone choices based on what time it is now.
> */
> function _theme_timed_timezones() {
> $timestamp = time();
> $zonelist = array(-11, -10, -9.5, -9, -8, -7, -6, -5, -4, -3.5, -3, -2, -1, 0, 1, 2, 3, 3.5, 4, 5, 5.5, 5.75, 6, 6.5, 7, 8, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 14);
> foreach ($zonelist as $offset) {
> $zone = $offset * _TZ_SECS;
> $zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone);
> }
> return $zones;
> }
>
> /**
> Return timezone choices as timezone labels.
> */
> function _theme_labeled_timezones() {
> return array(
> +12 *_TZ_SECS => '+1200=IDLE=NZST=NZT=Y',
> +11 *_TZ_SECS => '+1100=X',
> +10 *_TZ_SECS => '+1000=EAST=GST=USSRZone9=W',
> +9 *_TZ_SECS => '+0900=JST=USSRZone8=V',
> +8 *_TZ_SECS => '+0800=CCT=USSRZone7=U',
> +7 *_TZ_SECS => '+0700=WAST=USSRZone6=T',
> +6 *_TZ_SECS => '+0600=USSRZone5=ZP6=S',
> +5 *_TZ_SECS => '+0500=USSRZone4=ZP5=R',
> +4 *_TZ_SECS => '+0400=USSRZone3=ZP4=Q',
> +3 *_TZ_SECS => '+0300=BT=USSRZone2=P',
> +2 *_TZ_SECS => '+0200=EET=USSRZone1=O',
> +1 *_TZ_SECS => '+0100=CET=FWT=MET=MEWT=SWT=N',
> 0 *_TZ_SECS => '+0000=GMT=UTC=WET=Z',
> -1 *_TZ_SECS => '-0100=WAT=A',
> -2 *_TZ_SECS => '-0200=AT=B',
> -3 *_TZ_SECS => '-0300=C',
> -3.5 *_TZ_SECS => '-0330=NST',
> -4 *_TZ_SECS => '-0400=AST=EDT=D',
> -5 *_TZ_SECS => '-0500=EST=CDT=E',
> -6 *_TZ_SECS => '-0600=CST=MDT=F',
> -7 *_TZ_SECS => '-0700=MST=PDT=G',
> -8 *_TZ_SECS => '-0800=PST=YDT=H',
> -9 *_TZ_SECS => '-0900=YST=HDT=I',
> -10 *_TZ_SECS => '-1000=AHST=CAT=HST=K',
> -11 *_TZ_SECS => '-1100=NT=L',
> -12 *_TZ_SECS => '-1200=IDLW=M'
> );
> }
>
>
138,145d197
< // date settings:
< $timestamp = time();
< $zonelist = array(-11, -10, -9.5, -9, -8, -7, -6, -5, -4, -3.5, -3, -2, -1, 0, 1, 2, 3, 3.5, 4, 5, 5.5, 5.75, 6, 6.5, 7, 8, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 14);
< foreach ($zonelist as $offset) {
< $zone = $offset * 3600;
< $zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone);
< }
<

CommentFileSizeAuthor
#4 system.patch.txt9.65 KBmda-1
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mda-1’s picture

Dries’s picture

Please attach a patch instead of including one in the description body. Setting this to "won't fix" for now.

Steven’s picture

Also, please use unified diff, it's easier to read.

mda-1’s picture

FileSize
9.65 KB

attached.

Steven’s picture

Hmm, the named list has less zones than the numbered list (which afaik includes every time zone on the planet). Also, the named list has horrible formatting.

mda-1’s picture

Well, most of the patch is still useful in that it exposes a reusable function for
choosing a timezone, and it defaults to a display style identical to the
current one.

Steven’s picture

I removed the duplication of the timezone list, but I did not apply the theming changes. They seem unnecessary and confusing.

Also, your patch included 2 extra changes (php info and site_extra). Pay more attention next time please.