function theme_clock in Clock 7
Same name and namespace in other branches
- 6 clock.module \theme_clock()
- 7.2 clock.theme.inc \theme_clock()
1 theme call to theme_clock()
- clock_block_view in ./
clock.module - Implements hook_block_view().
File
- ./
clock.module, line 245
Code
function theme_clock($variables) {
// Initialize the variables.
$time_zone = $variables['time_zone'];
$date_format = $variables['date_format'];
$update = $variables['update'];
if ($time_zone == 'Local' || $update == 1) {
$local = 0;
if ($time_zone == 'Local') {
$local = 1;
// Use the site time zone as a fallback for non-JavaScript users.
$time_zone = variable_get('date_default_timezone', 'UTC');
}
drupal_add_js(drupal_get_path('module', 'clock') . '/clock.js');
// Pass the needed variables to JavaScript.
// Create a time string, from which JavaScript can create a date. The time
// string contains the month name, which needs to be in English.
$time = date_format_date(date_now($time_zone), 'custom', 'F j, Y H:i:s', 'en');
// Get the name of the offset, e.g. 'GMT'.
$offset_name = date_format_date(date_now($time_zone), 'custom', 'T');
// Get the time zone offset in seconds.
$offset_seconds = date_format_date(date_now($time_zone), 'custom', 'Z');
// Get Daylight Savings Time information. '1' for yes, '0' for no.
$daylight_savings_time = date_format_date(date_now($time_zone), 'custom', 'I');
drupal_add_js(array(
'time_zone' => $time_zone,
'date_format' => $date_format,
'update' => $update,
'local' => $local,
'offset_name' => $offset_name,
'offset_seconds' => $offset_seconds,
'daylight_savings_time' => $daylight_savings_time,
), 'setting');
}
// Create a date object with the correct timezone and format it with the correct date format.
$clock = date_format_date(date_now($time_zone), 'custom', $date_format);
return '<div class="clock">' . $clock . '</div>';
}