@@ -1075,12 +1075,29 @@ public static function i18nFormat($date, $format = null, $default = false, $time
1075
1075
* Or one of DateTimeZone class constants (PHP 5.3 and above)
1076
1076
* @param string $country A two-letter ISO 3166-1 compatible country code.
1077
1077
* This option is only used when $filter is set to DateTimeZone::PER_COUNTRY (available only in PHP 5.3 and above)
1078
- * @param bool $group If true (default value) groups the identifiers list by primary region
1078
+ * @param bool|array $options If true (default value) groups the identifiers list by primary region.
1079
+ * Otherwise, an array containing `group`, `abbr`, `before`, and `after` keys.
1080
+ * Setting `group` and `abbr` to true will group results and append timezone
1081
+ * abbreviation in the display value. Set `before` and `after` to customize
1082
+ * the abbreviation wrapper.
1079
1083
* @return array List of timezone identifiers
1080
1084
* @since 2.2
1081
1085
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::listTimezones
1082
1086
*/
1083
- public static function listTimezones ($ filter = null , $ country = null , $ group = true ) {
1087
+ public static function listTimezones ($ filter = null , $ country = null , $ options = array ()) {
1088
+ if (is_bool ($ options )) {
1089
+ $ options = array (
1090
+ 'group ' => $ options ,
1091
+ );
1092
+ }
1093
+ $ options = array_merge (array (
1094
+ 'group ' => true ,
1095
+ 'abbr ' => false ,
1096
+ 'before ' => ' - ' ,
1097
+ 'after ' => null ,
1098
+ ), $ options );
1099
+ $ group = $ options ['group ' ];
1100
+
1084
1101
$ regex = null ;
1085
1102
if (is_string ($ filter )) {
1086
1103
$ regex = $ filter ;
@@ -1108,12 +1125,23 @@ public static function listTimezones($filter = null, $country = null, $group = t
1108
1125
1109
1126
if ($ group ) {
1110
1127
$ return = array ();
1128
+ $ now = time ();
1129
+ $ before = $ options ['before ' ];
1130
+ $ after = $ options ['after ' ];
1111
1131
foreach ($ identifiers as $ key => $ tz ) {
1132
+ $ abbr = null ;
1133
+ if ($ options ['abbr ' ]) {
1134
+ $ dateTimeZone = new DateTimeZone ($ tz );
1135
+ $ trans = $ dateTimeZone ->getTransitions ($ now , $ now );
1136
+ $ abbr = isset ($ trans [0 ]['abbr ' ]) ?
1137
+ $ before . $ trans [0 ]['abbr ' ] . $ after :
1138
+ null ;
1139
+ }
1112
1140
$ item = explode ('/ ' , $ tz , 2 );
1113
1141
if (isset ($ item [1 ])) {
1114
- $ return [$ item [0 ]][$ tz ] = $ item [1 ];
1142
+ $ return [$ item [0 ]][$ tz ] = $ item [1 ] . $ abbr ;
1115
1143
} else {
1116
- $ return [$ item [0 ]] = array ($ tz => $ item [0 ]);
1144
+ $ return [$ item [0 ]] = array ($ tz => $ item [0 ] . $ abbr );
1117
1145
}
1118
1146
}
1119
1147
return $ return ;
0 commit comments