function views_handler_field_profile_date::render

Display a profile field of type 'date'.

Overrides views_handler_field_date::render

File

modules/profile/views_handler_field_profile_date.inc, line 30

Class

views_handler_field_profile_date
Field handler display a profile date.

Code

public function render($values) {
    $value = $this->get_value($values);
    if (!$value) {
        return;
    }
    $value = unserialize($value);
    $format = $this->options['date_format'];
    switch ($format) {
        case 'custom':
            $format = $this->options['custom_date_format'];
            break;
        case 'small':
            $format = variable_get('date_format_short', 'm/d/Y - H:i');
            break;
        case 'medium':
            $format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
            break;
        case 'large':
            $format = variable_get('date_format_long', 'l, F j, Y - H:i');
            break;
    }
    // Note: Avoid PHP's date() because it does not handle dates before
    // 1970 on Windows. This would make the date field useless for e.g.
    // birthdays.
    // But we *can* deal with non-year stuff.
    $date = gmmktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
    $replace = array(
        // day.
'd' => sprintf('%02d', $value['day']),
        'D' => NULL,
        'l' => NULL,
        'N' => NULL,
        'S' => gmdate('S', $date),
        'w' => NULL,
        'j' => $value['day'],
        // month.
'F' => gmdate('F', $date),
        'm' => sprintf('%02d', $value['month']),
        'M' => gmdate('M', $date),
        'n' => gmdate('n', $date),
        'Y' => $value['year'],
        'y' => substr($value['year'], 2, 2),
        // Kill time stuff.
'a' => NULL,
        'A' => NULL,
        'g' => NULL,
        'G' => NULL,
        'h' => NULL,
        'H' => NULL,
        'i' => NULL,
        's' => NULL,
        ':' => NULL,
        'T' => NULL,
        ' - ' => NULL,
        ':' => NULL,
    );
    return strtr($format, $replace);
}