Exemplo n.º 1
0
 /**
  * Generate ISO 8601 date string (RFC 3339)
  */
 public function format_date($time)
 {
     static $zone_offset;
     static $offset_string;
     if (empty($offset_string)) {
         $zone_offset = $this->user->create_datetime()->getOffset();
         $offset_string = src_format_timezone_offset($zone_offset);
     }
     return gmdate("Y-m-d\\TH:i:s", $time + $zone_offset) . $offset_string;
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function get_profile_value($field_value, $field_data)
 {
     $date = explode('-', $field_value);
     $day = isset($date[0]) ? (int) $date[0] : 0;
     $month = isset($date[1]) ? (int) $date[1] : 0;
     $year = isset($date[2]) ? (int) $date[2] : 0;
     if (!$day && !$month && !$year && !$field_data['field_show_novalue']) {
         return null;
     } else {
         if ($day && $month && $year) {
             // Date should display as the same date for every user regardless of timezone
             return $this->user->create_datetime()->setDate($year, $month, $day)->setTime(0, 0, 0)->format($this->user->lang['DATE_FORMAT'], true);
         }
     }
     return $field_value;
 }
Exemplo n.º 3
0
/**
* Options to pick a timezone and date/time
*
* @param	\src\template\template $template	src template object
* @param	\src\user	$user				Object of the current user
* @param	string		$default			A timezone to select
* @param	boolean		$truncate			Shall we truncate the options text
*
* @return		array		Returns an array containing the options for the time selector.
*/
function src_timezone_select($template, $user, $default = '', $truncate = false)
{
    static $timezones;
    $default_offset = '';
    if (!isset($timezones)) {
        $unsorted_timezones = src_get_timezone_identifiers($default);
        $timezones = array();
        foreach ($unsorted_timezones as $timezone) {
            $tz = new DateTimeZone($timezone);
            $dt = $user->create_datetime('now', $tz);
            $offset = $dt->getOffset();
            $current_time = $dt->format($user->lang['DATETIME_FORMAT'], true);
            $offset_string = src_format_timezone_offset($offset, true);
            $timezones['UTC' . $offset_string . ' - ' . $timezone] = array('tz' => $timezone, 'offset' => $offset_string, 'current' => $current_time);
            if ($timezone === $default) {
                $default_offset = 'UTC' . $offset_string;
            }
        }
        unset($unsorted_timezones);
        uksort($timezones, 'src_tz_select_compare');
    }
    $tz_select = $opt_group = '';
    foreach ($timezones as $key => $timezone) {
        if ($opt_group != $timezone['offset']) {
            // Generate tz_select for backwards compatibility
            $tz_select .= $opt_group ? '</optgroup>' : '';
            $tz_select .= '<optgroup label="' . $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']) . '">';
            $opt_group = $timezone['offset'];
            $template->assign_block_vars('timezone_select', array('LABEL' => $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']), 'VALUE' => $key . ' - ' . $timezone['current']));
            $selected = !empty($default_offset) && strpos($key, $default_offset) !== false ? ' selected="selected"' : '';
            $template->assign_block_vars('timezone_date', array('VALUE' => $key . ' - ' . $timezone['current'], 'SELECTED' => !empty($selected), 'TITLE' => $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current'])));
        }
        $label = $timezone['tz'];
        if (isset($user->lang['timezones'][$label])) {
            $label = $user->lang['timezones'][$label];
        }
        $title = $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $label);
        if ($truncate) {
            $label = truncate_string($label, 50, 255, false, '...');
        }
        // Also generate timezone_select for backwards compatibility
        $selected = $timezone['tz'] === $default ? ' selected="selected"' : '';
        $tz_select .= '<option title="' . $title . '" value="' . $timezone['tz'] . '"' . $selected . '>' . $label . '</option>';
        $template->assign_block_vars('timezone_select.timezone_options', array('TITLE' => $title, 'VALUE' => $timezone['tz'], 'SELECTED' => !empty($selected), 'LABEL' => $label));
    }
    $tz_select .= '</optgroup>';
    return $tz_select;
}