Index: CHANGELOG.txt =================================================================== RCS file: /cvs/drupal/contributions/modules/clock/CHANGELOG.txt,v retrieving revision 1.8 diff -u -p -r1.8 CHANGELOG.txt --- CHANGELOG.txt 3 May 2010 16:15:07 -0000 1.8 +++ CHANGELOG.txt 25 Jun 2010 21:42:16 -0000 @@ -2,6 +2,8 @@ Clock 7.x-1.x-dev ---------------------- +- #XXXXXX: General clean-up, remove t() from test file, refactor to only use + three variables, consistent variable naming - #706594: Depend on Libraries API. - #706602: Initial port to Drupal 7 Index: README.txt =================================================================== RCS file: /cvs/drupal/contributions/modules/clock/README.txt,v retrieving revision 1.2 diff -u -p -r1.2 README.txt --- README.txt 3 May 2010 16:24:37 -0000 1.2 +++ README.txt 25 Jun 2010 21:42:16 -0000 @@ -1,25 +1,29 @@ ; $Id: README.txt,v 1.2 2010/05/03 16:24:37 tstoeckler Exp $ -/** - * Installation - */ +/** + * Installation + */ 1. Obtain the "jQuery Timers" library from - http://plugins.jquery.com/project/timers. Current version: 1.2.0. - -2. Rename the "jquery.timers-1.2.js.txt" file to "jquery.timers.js". - + http://plugins.jquery.com/project/timers. Current version: 1.2.0. + +2. Rename the "jquery.timers-1.2.js.txt" file to "jquery.timers.js". + 3. If you haven't already, create a 'libraries' directory in your sites folder (sites/all, sites/default, sites/). 4. Create a 'jquerytimers' folder inside the 'libraries' directory. 5. Upload the "jquery.timers.js" file into the 'jquerytimers' - directory. - + directory. + 6. If you haven't already, download the "Date" project (http://drupal.org/project/date) and install it as usual. Current - version: 6.x-2.4. - + version: 7.x-1.x-dev. + +7. If you haven't already, download the "Libraries API" project + (http://drupal.org/project/libraries) and install it as usual. Current + version: 7.x-1.x-dev. + 7. Enable Clock module as usual. /** Index: clock.info =================================================================== RCS file: /cvs/drupal/contributions/modules/clock/clock.info,v retrieving revision 1.7 diff -u -p -r1.7 clock.info --- clock.info 3 May 2010 16:17:49 -0000 1.7 +++ clock.info 25 Jun 2010 21:42:16 -0000 @@ -1,6 +1,6 @@ ; $Id: clock.info,v 1.7 2010/05/03 16:17:49 tstoeckler Exp $ name = Clock -description = Provides a block displaying the time of a selected time zone. +description = Provides a block displaying the current time. core = 7.x package = Date/Time dependencies[] = block Index: clock.install =================================================================== RCS file: /cvs/drupal/contributions/modules/clock/clock.install,v retrieving revision 1.6 diff -u -p -r1.6 clock.install --- clock.install 3 May 2010 16:22:04 -0000 1.6 +++ clock.install 25 Jun 2010 21:42:16 -0000 @@ -11,13 +11,8 @@ */ function clock_uninstall() { // Delete all clock variables. - variable_del('clock_timezone_type'); - variable_del('clock_custom_timezone'); - variable_del('clock_date_format_type'); - variable_del('clock_custom_date_format'); - variable_del('clock_js'); - // Delete the clock block from the blocks table. - // Remove this if http://drupal.org/node/335240 gets in. - db_query("DELETE FROM {blocks} WHERE module = 'clock'"); + variable_del('clock_time_zone'); + variable_del('clock_date_type'); + variable_del('clock_update'); } Index: clock.js =================================================================== RCS file: /cvs/drupal/contributions/modules/clock/clock.js,v retrieving revision 1.14 diff -u -p -r1.14 clock.js --- clock.js 28 May 2010 00:05:12 -0000 1.14 +++ clock.js 25 Jun 2010 21:42:16 -0000 @@ -11,7 +11,11 @@ Drupal.behaviors.clockDisplay = { attach: function (context, settings) { - // Gets the correct variables from PHP. + // Get the correct variables from PHP. + // The name of the timezone, e.g. 'Europe/London'. + var timezoneName = Drupal.settings['time_zone']; + // A PHP date format string. + var dateFormat = Drupal.settings['date_format']; // Whether or not to update the clock continuously. var update = Drupal.settings['update']; // Whether or not to use the user's local time zone. @@ -20,18 +24,13 @@ Drupal.behaviors.clockDisplay = { // Note that due to JavaScript's inferior time zone handling, time zone // related date formatters will return the time zone of the Drupal site, not // the visiting user if the time zone is set to 'Local'. - var date = Drupal.settings['local'] ? new Date() : new Date(Drupal.settings['time']); - // The name of the timezone, e.g. 'Europe/London'. - var timezoneName = Drupal.settings['timezone_name']; + var date = (Drupal.settings['local'] == 1) ? new Date() : new Date(Drupal.settings['time']); // The name of the offset, e.g. 'GMT'. var offsetName = Drupal.settings['offset_name']; // The time zone offset in seconds. var offsetSeconds = Drupal.settings['offset_seconds']; // Daylight Savings Time information. '1' for yes, '0' for no. var daylightSavingsTime = Drupal.settings['daylight_savings_time']; - // A PHP date format string. - var dateFormat = Drupal.settings['date_format']; - // Create an array containing month names. var monthNames = new Array(); @@ -108,12 +107,12 @@ Drupal.behaviors.clockDisplay = { clock = formatDate(date, dateFormat, timezone, monthNames, weekdayNames); $('div.clock').html(clock); - if (update == '1') { + if (update == 1) { - // Recalculate the date every second. '.everyTime' is provided by jQuery Timers. + // Recalculate the date every second. 'everyTime' is provided by jQuery Timers. $(document).everyTime(1000, function() { - // Add 1 second to the time. + // Add 1 second (1000 milliseconds) to the time. var clockTimestamp = date.getTime(); clockTimestamp = clockTimestamp + 1000; date = new Date(clockTimestamp); Index: clock.module =================================================================== RCS file: /cvs/drupal/contributions/modules/clock/clock.module,v retrieving revision 1.15 diff -u -p -r1.15 clock.module --- clock.module 28 May 2010 00:05:12 -0000 1.15 +++ clock.module 25 Jun 2010 21:42:17 -0000 @@ -13,13 +13,13 @@ function clock_help($path, $arg) { $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Administering the clock') . '
'; - $output .= '
' . t('Since the clock is a block, it can be administered via its block settings page which is accessible from the block administration page. In addition to the usual block configuration options there are a number of options.', array('@clock-settings' => '/admin/build/block/configure/clock/clock', '@block-admin' => '/admin/build/block')) . '
'; + $output .= '
' . t('Since the clock is a block, it can be administered via its block settings page which is accessible from the block administration page. In addition to the usual block configuration options there are a number of options.', array('@clock-settings' => url('admin/structure/block/manage/clock/clock/configure'), '@block-admin' => url('admin/structure/block'))) . '
'; $output .= '
'; $output .= '
' . t('Time zone') . '
'; $output .= '
' . t('The time zone of the clock.') . '
'; $output .= '
'; $output .= '
' . t('Site time zone') . '
'; - $output .= '
' . t('The time zone that has been set on the date and time settings page.', array('@date-admin' => '/admin/settings/date-time')) . '
'; + $output .= '
' . t('The time zone that has been set on the regional settings page.', array('@regional-admin' => url('admin/config/regional/settings'))) . '
'; $output .= '
' . t('User time zone') . '
'; $output .= '
' . t('This option will only show up, if user-configurable time zones are enabled. The time zone the user has selected.') . '
'; $output .= '
' . t('Local time zone') . '
'; @@ -28,17 +28,7 @@ function clock_help($path, $arg) { $output .= '
' . t('A custom time zone that can be selected in the select box below the radio buttons.') . '
'; $output .= '
'; $output .= '
' . t('Date format') . '
'; - $output .= '
' . t('The date format that the clock is to be displayed in.') . '
'; - $output .= '
'; - $output .= '
' . t('Short date format') . '
'; - $output .= '
' . t('The short date format that has been set on the date format configuration page. The expected output (not necessarily in the correct timezone) is shown in parentheses.', array('@format-admin' => '/admin/settings/date-time/formats')). '
'; - $output .= '
' . t('Medium date format') . '
'; - $output .= '
' . t('The medium date format that has been set on the date format configuration page. The expected output (not necessarily in the correct timezone) is shown in parentheses.', array('@format-admin' => '/admin/settings/date-time/formats')). '
'; - $output .= '
' . t('Long date format') . '
'; - $output .= '
' . t('The long date format that has been set on the date format configuration page. The expected output (not necessarily in the correct timezone) is shown in parentheses.', array('@format-admin' => '/admin/settings/date-time/formats')). '
'; - $output .= '
' . t('Custom date format') . '
'; - $output .= '
' . t('This options will only show up, if there are custom date formats. A custom date format can be selected in the select box below the radio buttons.', array('@custom-formats' => '/admin/settings/date-time/formats/custom')) . '
'; - $output .= '
'; + $output .= '
' . t('The date format that the clock is to be displayed in. All of the date types that have been set on the date and time settings page are available here.', array('@format-admin' => url('admin/config/regional/date-time'))) . '
'; $output .= '
' . t('JavaScript updating') . '
'; $output .= '
' . t('Whether or not the clock should be updated continuously via JavaScript. This is especially useful if seconds are displayed. It only works if the visitor has JavaScript enabled.') . '
'; $output .= '
'; @@ -66,60 +56,60 @@ function clock_block_configure($delta = if ($delta == 'clock') { // Time zone options. - $form['timezone'] = array( + $time_zone = variable_get('clock_time_zone', 1); + // If the time zone is not set to the integer values 1, 2 or 3 corresponding + // 'Site time zone', 'User time zone' and 'Local time zone' it is a custom + // time zone, which has the integer value 4. + $time_zone_type = (array_search($time_zone, array(1, 2, 3))) ? array_search($time_zone, array(1, 2, 3)) : 4; + $custom_time_zone = ($time_zone_type == 4) ? $time_zone : 'UTC'; + $form['time_zone_type'] = array( '#type' => 'radios', '#title' => t('Time zone settings'), - '#weight' => 1, '#options' => array( - '1' => t('Site time zone'), - '3' => t('Local time zone'), - '4' => t('Custom time zone'), + 1 => t('Site time zone'), + 3 => t('Local time zone'), + 4 => t('Custom time zone'), ), - '#default_value' => variable_get('clock_timezone_type', '1'), + '#default_value' => $time_zone_type, ); // In case of user-configurable timezones show it as an option. if (variable_get('configurable_timezones', 1) == 1) { - $form['timezone']['#options'] = array( - '1' => t('Site time zone'), - '2' => t('User time zone'), - '3' => t('Local time zone'), - '4' => t('Custom time zone'), - ); + $form['time_zone_type']['#options'][2] = t('User time zone'); } - $form['custom_timezone'] = array( + $form['time_zone_custom'] = array( '#type' => 'select', - '#multiple' => FALSE, - '#weight' => 2, - '#default_value' => variable_get('clock_custom_timezone', 'UTC'), '#options' => date_timezone_names(), + '#default_value' => $custom_time_zone, // Show the select list only if "Custom time zone" is selected. '#states' => array( 'visible' => array( - ':input[name="timezone"]' => array('value' => '4'), + ':input[name="timezone"]' => array('value' => 4), ), ), ); - // Date format options. + // Date type options. // Format the current time with each date type to display them in the form. + // If the user has changed the time zone since the last page load, the + // formatted time is displayed in the wrong, old time zone. $date_types = array(); foreach(system_get_date_types() as $date_type => $info) { - $date_types[$date_type] = $info['title'] . ' (' . date_format_date(date_now(clock_get_timezone()), 'custom', clock_get_date_format($date_type)) . ')'; + $date_types[$date_type] = $info['title'] . ' (' . date_format_date(date_now(clock_get_timezone()), 'custom', variable_get('date_format_' . $date_type, key(system_get_date_formats()))) . ')'; } - $form['date_format'] = array( + $form['date_type'] = array( '#type' => 'radios', '#title' => t('Date format settings'), '#weight' => 3, - '#default_value' => variable_get('clock_date_format_type', 'long'), + '#default_value' => variable_get('clock_date_type', 'long'), '#options' => $date_types, ); - // JavaScript options. - $form['js'] = array( + // Update options. + $form['update'] = array( '#type' => 'checkbox', '#title' => t('Use JavaScript to continuously update the clock'), '#weight' => 5, - '#default_value' => variable_get('clock_js', '1'), + '#default_value' => variable_get('clock_update', '1'), ); return $form; @@ -131,12 +121,10 @@ function clock_block_configure($delta = */ function clock_block_save($delta = '', $edit = array()) { if ($delta == 'clock') { - variable_set('clock_timezone_type', $edit['timezone']); - if ($edit['timezone'] == '4') { - variable_set('clock_custom_timezone', $edit['custom_timezone']); - } - variable_set('clock_date_format_type', $edit['date_format']); - variable_set('clock_js', $edit['js']); + $time_zone = ($edit['time_zone_type'] == 4) ? $edit['time_zone_custom'] : $edit['time_zone_type']; + variable_set('clock_time_zone', $time_zone); + variable_set('clock_date_type', $edit['date_type']); + variable_set('clock_update', $edit['update']); return; } } @@ -148,7 +136,7 @@ function clock_block_view($delta = '') { if ($delta == 'clock') { $block = array(); $block['subject'] = 'Clock'; - $block['content'] = theme_clock(clock_get_timezone(), clock_get_date_format(), variable_get('clock_js', '1')); + $block['content'] = theme_clock(clock_get_timezone(), clock_get_date_format(), variable_get('clock_update', TRUE)); return $block; } } @@ -158,51 +146,37 @@ function clock_block_view($delta = '') { * * @return * The name of the timezone, NULL if the user's time zone is to be used or - * 'Local' is the user's local time is to be used. + * 'Local' if the user's local time is to be used. */ function clock_get_timezone() { - $type = variable_get('clock_timezone_type', '1'); - switch ($type) { + $time_zone = variable_get('clock_time_zone', 1); + switch ($time_zone) { // Site time zone. - case '1': - $timezone = variable_get('date_default_timezone', 'UTC'); + case 1: + $time_zone = variable_get('date_default_timezone', 'UTC'); break; // User time zone. - case '2': - $timezone = NULL; + case 2: + $time_zone = NULL; break; // Local time zone. - case '3': - $timezone = 'Local'; - break; - // Custom time zone. - case '4': - $timezone = variable_get('clock_custom_timezone', 'UTC'); + case 3: + $time_zone = 'Local'; break; } - return $timezone; + return $time_zone; } /** * Gets the correct date format. * - * @param $type - * (optional) The format type. - * * @return - * If $type was specified, the date format of the specified format type. If - * $type is omitted, the date format of the format type used for the clock. + * The date format of the date type used for the clock. */ -function clock_get_date_format($type = FALSE) { - if (!$type) { - $type = variable_get('clock_date_format_type', 'long'); - } - $date_format = variable_get('date_format_' . $type, ''); - // If the date format has not been specifically set, load the default. - if (!$date_format) { - $date_formats = array_keys(system_get_date_formats($type)); - $date_format = array_shift($date_formats); - } +function clock_get_date_format() { + $date_type = variable_get('clock_date_type', 'long'); + $date_formats = array_keys(system_get_date_formats($date_type)); + $date_format = variable_get('date_format_' . $date_type, array_shift($date_formats)); return $date_format; } @@ -213,9 +187,9 @@ function clock_theme() { return array( 'clock' => array( 'variables' => array( - 'timezone' => 'UTC', - 'date_format' => 'short', - 'js' => '1', + 'time_zone' => 'UTC', + 'date_format' => '', + 'update' => 1, ), ), ); @@ -224,14 +198,15 @@ function clock_theme() { /* * Provide a default implementation of theme_clock(). */ -function theme_clock($timezone, $date_format, $update) { +function theme_clock($time_zone, $date_format, $update) { - if ($update == '1' || $timezone == 'Local') { + if ($time_zone == 'Local' || $update == 1) { - if ($timezone == 'Local') { - $local = TRUE; + $local = 0; + if ($time_zone == 'Local') { + $local = 1; // Use the site time zone as a fallback for non-JavaScript users. - $timezone = variable_get('date_default_timezone', 'UTC'); + $time_zone = variable_get('date_default_timezone', 'UTC'); } // Load the jQuery Timers library and clock.js @@ -240,32 +215,31 @@ function theme_clock($timezone, $date_fo // Create variables that are needed for the JavaScript time calculation. // Create a time string. - $time = date_format_date(date_now($timezone), $type = 'custom', $format = 'F j, Y H:i:s'); + $time = date_format_date(date_now($time_zone), $type = 'custom', $format = 'F j, Y H:i:s'); + // Get the name of the offset, e.g. 'GMT'. + $offset_name = date_format_date(date_now($time_zone), $type = 'custom', $format = 'T'); // Get the time zone offset in seconds. - $offset_seconds = date_format_date(date_now($timezone), $type = 'custom', $format = 'Z'); + $offset_seconds = date_format_date(date_now($time_zone), $type = 'custom', $format = 'Z'); // Get Daylight Savings Time information. '1' for yes, '0' for no. - $daylight_savings_time = date_format_date(date_now($timezone), $type = 'custom', $format = 'I'); - // Get the name of the offset, e.g. 'GMT'. - $offset_name = date_format_date(date_now($timezone), $type = 'custom', $format = 'T'); - + $daylight_savings_time = date_format_date(date_now($time_zone), $type = 'custom', $format = 'I'); // Pass the variables to JavaScript. drupal_add_js(array( - 'update' => $update, - 'local' => isset($local) ? TRUE : FALSE, - 'time' => $time, - 'timezone_name' => $timezone, - 'offset_name' => $offset_name, - 'offset_seconds' => $offset_seconds, + 'time_zone' => $time_zone, + 'date_format' => $date_format, + 'update' => $update, + 'local' => $local, + 'time' => $time, + 'offset_name' => $offset_name, + 'offset_seconds' => $offset_seconds, 'daylight_savings_time' => $daylight_savings_time, - 'date_format' => $date_format, ), 'setting'); } // Create a date object with the correct timezone and format it with the correct date format. - $clock = date_format_date(date_now($timezone), 'custom', $date_format); - + $clock = date_format_date(date_now($time_zone), 'custom', $date_format); $output = '
' . $clock . '
'; return $output; } + Index: clock.test =================================================================== RCS file: /cvs/drupal/contributions/modules/clock/clock.test,v retrieving revision 1.7 diff -u -p -r1.7 clock.test --- clock.test 28 May 2010 00:05:12 -0000 1.7 +++ clock.test 25 Jun 2010 21:42:17 -0000 @@ -10,9 +10,9 @@ class ClockBlockTestCase extends DrupalW public static function getInfo() { return array( - 'name' => t('Clock module tests'), - 'description' => t('Ensure that the clock block functions properly.'), - 'group' => t('Clock'), + 'name' => 'Clock module tests', + 'description' => 'Ensure that the clock block and the configuration form functions properly.', + 'group' => 'Clock', ); } @@ -32,10 +32,10 @@ class ClockBlockTestCase extends DrupalW $this->drupalGet('admin/config/regional/settings'); // Test the default display of the clock. $clock = date_format_date(date_now(variable_get('date_default_timezone', 0)), 'long'); - $this->assertText($clock, t('Ensure that the clock is correctly displayed by default.')); - $edit['timezone'] = '3'; + $this->assertText($clock, 'Ensure that the clock is correctly displayed by default.'); + $edit['time_zone_type'] = 3; $this->drupalPost('admin/structure/block/manage/clock/clock/configure', $edit, 'Save block'); - $this->assertText($clock, t('Ensure that the clock falls back to the site time with Local time zone enabled and without JavaScript.')); + $this->assertText($clock, 'Ensure that the clock falls back to the site time with Local time zone enabled and without JavaScript.'); // Test the user time zone. $edit = array(); @@ -43,18 +43,18 @@ class ClockBlockTestCase extends DrupalW $this->drupalPost('user/' . variable_get('test_user_id', '1') . '/edit', $edit, 'Save'); // Set the clock block to display the user time zone. $edit = array(); - $edit['timezone'] = '2'; + $edit['time_zone_type'] = 2; $this->drupalPost('admin/structure/block/manage/clock/clock/configure', $edit, 'Save block'); $clock = date_format_date(date_now('Pacific/Fiji'), 'long'); - $this->assertText($clock, t('Ensure that the clock is correctly displayed in the user time zone.')); + $this->assertText($clock, 'Ensure that the clock is correctly displayed in the user time zone.'); // Test a custom time zone. $edit = array(); - $edit['timezone'] = '4'; - $edit['custom_timezone'] = 'Africa/Lubumbashi'; + $edit['time_zone_type'] = 4; + $edit['time_zone_custom'] = 'Africa/Lubumbashi'; $this->drupalPost('admin/structure/block/manage/clock/clock/configure', $edit, 'Save block'); $clock = date_format_date(date_now('Africa/Timbuktu'), 'long'); - $this->assertText($clock, t('Ensure that the clock is correctly displayed in a custom date format')); + $this->assertText($clock, 'Ensure that the clock is correctly displayed in a custom date format'); // Test the clock block in all format types. // Configure a custom date format. We leave the 'r' formatter out, because @@ -69,39 +69,22 @@ class ClockBlockTestCase extends DrupalW $edit['date_format'] = 'aAbBcCdDeEfFgGhHiIjJlLmMnNoOpPqQRsStTuUvVwWxXyYzZ'; $this->drupalPost('admin/config/regional/date-time/types/add', $edit, 'Add date type'); foreach (system_get_date_types() as $type => $info) { - $format = variable_get('date_format_' . $type, '') ? variable_get('date_format_' . $type, '') : key(system_get_date_formats($type)); + $format = variable_get('date_format_' . $type, key(system_get_date_formats($type))); $edit = array(); - $edit['date_format'] = $type; + $edit['date_type'] = $type; $this->drupalPost('admin/structure/block/manage/clock/clock/configure', $edit, 'Save block'); $clock = date_format_date(date_now('Africa/Lubumbashi'), 'custom', $format); - $this->assertText($clock, t('Ensure that the clock is correctly displayed in the @type date format type.', array('@type' => $info['title']))); + $title = $info['title']; + $this->assertText($clock, "Ensure that the clock is correctly displayed in the $title date format type."); } } -} - -class ClockConfigureTestCase extends DrupalWebTestCase { - - public static function getInfo() { - return array( - 'name' => t('Clock interface tests'), - 'description' => t('Ensure that the user interface functions correctly.'), - 'group' => t('Clock'), - ); - } - - public function setUp() { - parent::setUp('block', 'date_api', 'clock'); - $privileged_user = $this->drupalCreateUser(array('administer blocks', 'administer site configuration')); - $this->drupalLogin($privileged_user); - } - public function testClockInterfaceUserTimezone() { $this->drupalGet('admin/structure/block/manage/clock/clock/configure'); - $this->assertText(t('User time zone'), t('Make sure the "User time zone" setting is available when user time zones are enabled.')); + $this->assertText('User time zone', "Make sure the 'User time zone' setting is available when user time zones are enabled."); variable_set('configurable_timezones', 0); $this->drupalGet('admin/structure/block/manage/clock/clock/configure'); - $this->assertNoText(t('User time zone'), t('Make sure the "User time zone" setting is not available when user time zones are disabled.')); + $this->assertNoText('User time zone', "Make sure the 'User time zone' setting is not available when user time zones are disabled."); } }