diff --git a/clock.module b/clock.module index ecbb519..500d669 100755 --- a/clock.module +++ b/clock.module @@ -108,10 +108,8 @@ function clock_block_configure($delta = '') { // the formatted time is displayed in the wrong, old time zone. $date_types = array(); foreach (system_get_date_types() as $date_type => $info) { - // Each date format type has a corresponding variable. If it is not set, - // get the list of date formats for that type and use the first one. - $date_format = variable_get('date_format_' . $date_type, key(system_get_date_formats($date_type))); - $date_types[$date_type] = $info['title'] . ' (' . date_format_date(date_now(_clock_get_timezone(TRUE)), 'custom', $date_format) . ')'; + $date_format = _clock_get_date_format($date_type); + $date_types[$date_type] = $info['title'] . ' (' . date_format_date(date_now(_clock_get_timezone(TRUE)), 'custom', $date_format) . ')'; } $form['date_type'] = array( '#type' => 'radios', @@ -203,14 +201,26 @@ function _clock_get_timezone($date_format_date = FALSE) { /** * Gets the correct date format. * + * @param $date_type + * (optional) The date type to return the date format for. If omitted, uses + * the date type which is set for the clock. + * * @return * The date format of the date type used for the clock. */ -function _clock_get_date_format() { - $date_type = variable_get('clock_date_type', 'long'); - // Each date format type has a corresponding variable. If it is not set, get - // the list of date formats for that type and use the first one. - $date_format = variable_get('date_format_' . $date_type, key(system_get_date_formats($date_type))); +function _clock_get_date_format($date_type = NULL) { + if (!isset($date_type)) { + $date_type = variable_get('clock_date_type', 'long'); + } + // Each date format type has a corresponding variable. If it is not set, + // get the list of date formats for that type and use the first one. We + // cannot use the fallback directly in variable_get(), because + // system_get_date_formats() can return FALSE for custom date types. In + // that case, the variable is always set, though. + $date_format = variable_get('date_format_' . $date_type, NULL); + if (!isset($date_format)) { + $date_format = key(system_get_date_formats($date_type)); + } return $date_format; }