You are here

function theme_clock in Clock 6

Same name and namespace in other branches
  1. 7.2 clock.theme.inc \theme_clock()
  2. 7 clock.module \theme_clock()

Formats a clock in HTML.

1 call to theme_clock()
clock_block in ./clock.module
Implements hook_block().

File

./clock.module, line 267
Functions to manage the display of a clock.

Code

function theme_clock($timezone, $date_format, $js) {
  if ($js == '1' || $timezone == 'Local') {
    if ($timezone == 'Local') {
      $local = TRUE;

      // Use the site time zone as a fallback for non-JavaScript users.
      $timezone = variable_get('date_default_timezone_name', 'UTC');
    }

    // 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($timezone), 'custom', 'F j, Y H:i:s', 'en');

    // Get the time zone offset in seconds.
    $offset_seconds = date_format_date(date_now($timezone), 'custom', 'Z');

    // Get Daylight Savings Time information. '1' for yes, '0' for no.
    $daylight_savings_time = date_format_date(date_now($timezone), 'custom', 'I');

    // Get the name of the offset, e.g. 'GMT'.
    $offset_name = date_format_date(date_now($timezone), 'custom', 'T');
    drupal_add_js(array(
      'update' => $js,
      'local' => isset($local) ? TRUE : FALSE,
      'offset_seconds' => $offset_seconds,
      'timezone_name' => $timezone,
      'daylight_savings_time' => $daylight_savings_time,
      'offset_name' => $offset_name,
      'date_format' => $date_format,
    ), 'setting');
    drupal_add_js(drupal_get_path('module', 'clock') . '/clock.js');
  }

  // Create a date object with the correct timezone and format it with the correct date format.
  $clock = date_format_date(date_now($timezone), $type = 'custom', $format = $date_format);
  $output = '<div class="clock">' . $clock . '</div>';
  return $output;
}