You are here

function partial_date_timezone_handling_correlation in Partial Date 7

Helper function to determine the correct timezone based on the timezone handling options used.

Parameters

string $timezone: Current timezone from the database or widget.

string $tz_handling: The timezone handling options that needs enforcing.

2 calls to partial_date_timezone_handling_correlation()
partial_date_generate_date in ./partial_date.admin.inc
This generates a date component based on the specified timestamp and timezone. This is used for deminstrational purposes only, and may fall back to the request timestamp and site timezone.
_partial_date_field_widget_form in ./partial_date.admin.inc
Implements hook_field_widget_form().

File

./partial_date.module, line 1057
Defines a date element that allows for any combination of date granularity settings.

Code

function partial_date_timezone_handling_correlation($timezone = '', $tz_handling = 'none') {
  global $user;

  // Override or return unchanged depending on the set action.
  switch ($tz_handling) {
    case 'utc':
      return 'UTC';
    case 'site':
      return variable_get('date_default_timezone', @date_default_timezone_get());
    case 'user':
      if (variable_get('configurable_timezones', 1) && !empty($user->timezone)) {
        return $user->timezone;
      }
      else {
        return variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT) ? '' : variable_get('date_default_timezone', '');
      }
    case 'date':
    case 'none':

      // Parse the existing timezone.
      $timezone = isset($timezone) ? $timezone : '';
      switch ($timezone) {
        case '--user--':
        case '--site--':
          $timezone = partial_date_timezone_handling_correlation($timezone, trim($timezone, '-'));
          break;
      }
      return $timezone;
    default:
      return '';
  }
}