From 9a8ebbb5a83bd703ab219f8e337256da5a5aaa9f Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Mon, 1 Dec 2014 23:12:42 +1100 Subject: [PATCH] Replace hard coded timezone with function from date module --- booking.admin.inc | 9 --------- booking.helper.inc | 24 ++++++++++++------------ booking.module | 4 ++-- booking.register.inc | 2 +- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/booking.admin.inc b/booking.admin.inc index c926e42..a318339 100644 --- a/booking.admin.inc +++ b/booking.admin.inc @@ -122,15 +122,6 @@ function booking_admin() { '#default_value' => variable_get('booking_default_country', 'Australia'), ); - $form['misc']['booking_local_timezone'] = array ( - '#type' => 'select', - '#title' => t('Select Local Time Zone'), - '#description' => t('Select time zone to use when calculating dates and times. This should match drupal\'s timezone definition'), - '#options' => _booking_country_options(), - '#default_value' => variable_get('booking_default_country', 'Australia'), - ); - - $form['misc']['booking_default_gender'] = array ( '#type' => 'select', '#title' => t('Select Default Gender'), diff --git a/booking.helper.inc b/booking.helper.inc index ca86f03..0eebcbe 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -170,8 +170,8 @@ function _booking_change_status($nid, $status_id) function _datearray_to_ts($date) { - date_default_timezone_set(TIMEZONE); - $tz = new DateTimeZone(TIMEZONE); + date_default_timezone_set(date_default_timezone(FALSE)); + $tz = new DateTimeZone(date_default_timezone(FALSE)); if (empty($date) || ($date['month'] == '' && $date['day'] == '' && $date['year'] == '')) return 0; @@ -188,8 +188,8 @@ function _datearray_to_ts($date) function _datetime_array_to_ts($date) { //watchdog('booking', 'Date-time Conversion: @info', array('@info' => var_export($date, TRUE))); - date_default_timezone_set(TIMEZONE); - $tz = new DateTimeZone(TIMEZONE); + date_default_timezone_set(date_default_timezone(FALSE)); + $tz = new DateTimeZone(date_default_timezone(FALSE)); if (empty($date) || ($date['month'] == '' && $date['day'] == '' && $date['year'] == '')) return 0; @@ -207,8 +207,8 @@ function _datetime_array_to_ts($date) function _date_to_ts($date) { $date_split = _booking_split_date($date); - date_default_timezone_set(TIMEZONE); - $tz = new DateTimeZone(TIMEZONE); + date_default_timezone_set(date_default_timezone(FALSE)); + $tz = new DateTimeZone(date_default_timezone(FALSE)); if ($date_split[0] == '-1' ) return 0; @@ -226,8 +226,8 @@ function _date_to_ts($date) { function _datetime_to_ts($date) { $date_split = _booking_split_date($date); - date_default_timezone_set(TIMEZONE); - $tz = new DateTimeZone(TIMEZONE); + date_default_timezone_set(date_default_timezone(FALSE)); + $tz = new DateTimeZone(date_default_timezone(FALSE)); if ($date_split[0] == '-1' ) return 0; @@ -268,8 +268,8 @@ function _datetime_to_ts_nonstrict($date) { return 0; } - date_default_timezone_set(TIMEZONE); - $tz = new DateTimeZone(TIMEZONE); + date_default_timezone_set(date_default_timezone(FALSE)); + $tz = new DateTimeZone(date_default_timezone(FALSE)); //$gmt_ts = mktime($date_split[5], $date_split[6], 0, $date_split[2], $date_split[1], $date_split[3]); $gmt_ts = mktime($hour, $minute, $second, $month, $day, $year); @@ -315,8 +315,8 @@ function _arrange_date($date) { function _booking_convert_ts($timestamp) { //load the timestamp - date_default_timezone_set(TIMEZONE); - $tz = new DateTimeZone(TIMEZONE); + date_default_timezone_set(date_default_timezone(FALSE)); + $tz = new DateTimeZone(date_default_timezone(FALSE)); $date = new DateTime("@$timestamp"); $date->setTimezone($tz); diff --git a/booking.module b/booking.module index c7a4a64..ab4a7c5 100644 --- a/booking.module +++ b/booking.module @@ -19,7 +19,7 @@ define('EVENTID', 1); define('BOOKING_PAYPAL_SUBMIT_URL', 'https://www.paypal.com/cgi-bin/webscr'); define('BOOKING_PAYPAL_SUBMIT_URL_SANDBOX', 'https://www.sandbox.paypal.com/cgi-bin/webscr'); define('BOOKING_PAYPAL_IPN_PATH', 'system/booking_paypal/ipn'); -define('TIMEZONE', 'Australia/Sydney'); +define('date_default_timezone(FALSE)', 'Australia/Sydney'); define('BOOKING_DEFAULT_STATE', 'NSW'); //define('CUSTOM_EMAIL_COUNT', 10); //define('STUDYGROUP_COUNT', 7); @@ -68,7 +68,7 @@ module_load_include('inc', 'booking', 'booking.rooms'); module_load_include('inc', 'booking', 'booking.rooms_admin'); function booking_init() { - date_default_timezone_set(TIMEZONE); + date_default_timezone_set(date_default_timezone(FALSE)); global $event; //reference - http://www.devdaily.com/drupal/drupal-7-sql-cheat-sheet-function-examples diff --git a/booking.register.inc b/booking.register.inc index 151c8b6..e1115df 100644 --- a/booking.register.inc +++ b/booking.register.inc @@ -56,7 +56,7 @@ function booking_form($node, &$form_state, $inserting = FALSE) { $status_options = array(); $payment_type_options = array(); $partner_options = array(); - date_default_timezone_set(TIMEZONE); + date_default_timezone_set(date_default_timezone(FALSE)); if (!empty($node)) {