Révision 6eb8d15f
Ajouté par Assos Assos il y a presque 10 ans
drupal7/sites/all/modules/views/handlers/views_handler_field_date.inc | ||
---|---|---|
16 | 16 |
|
17 | 17 |
$options['date_format'] = array('default' => 'small'); |
18 | 18 |
$options['custom_date_format'] = array('default' => ''); |
19 |
$options['second_date_format_custom'] = array('default' => ''); |
|
20 |
$options['second_date_format'] = array('default' => 'small'); |
|
19 | 21 |
$options['timezone'] = array('default' => ''); |
20 | 22 |
|
21 | 23 |
return $options; |
... | ... | |
36 | 38 |
'custom' => t('Custom'), |
37 | 39 |
'raw time ago' => t('Time ago'), |
38 | 40 |
'time ago' => t('Time ago (with "ago" appended)'), |
41 |
'today time ago' => t('Time ago (with "ago" appended) for today\'s date, but not for other dates'), |
|
39 | 42 |
'raw time hence' => t('Time hence'), |
40 | 43 |
'time hence' => t('Time hence (with "hence" appended)'), |
41 | 44 |
'raw time span' => t('Time span (future dates have "-" prepended)'), |
... | ... | |
49 | 52 |
'#title' => t('Custom date format'), |
50 | 53 |
'#description' => t('If "Custom", see the <a href="@url" target="_blank">PHP manual</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.', array('@url' => 'http://php.net/manual/function.date.php')), |
51 | 54 |
'#default_value' => isset($this->options['custom_date_format']) ? $this->options['custom_date_format'] : '', |
52 |
'#dependency' => array('edit-options-date-format' => array('custom', 'raw time ago', 'time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span')), |
|
55 |
'#dependency' => array('edit-options-date-format' => array('custom', 'raw time ago', 'time ago', 'today time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span')),
|
|
53 | 56 |
); |
57 |
$form['second_date_format'] = array( |
|
58 |
'#type' => 'select', |
|
59 |
'#title' => t('Second date format'), |
|
60 |
'#options' => $date_formats + array( |
|
61 |
'custom' => t('Custom'), |
|
62 |
), |
|
63 |
'#description' => t('The date format which will be used for rendering dates other than today.'), |
|
64 |
'#default_value' => isset($this->options['second_date_format']) ? $this->options['second_date_format'] : 'small', |
|
65 |
'#dependency' => array('edit-options-date-format' => array('today time ago')), |
|
66 |
); |
|
67 |
$form['second_date_format_custom'] = array( |
|
68 |
'#type' => 'textfield', |
|
69 |
'#title' => t('Custom date format of second date'), |
|
70 |
'#description' => t('If "Custom" is selected in "Second date format", see the <a href="@url" target="_blank">PHP manual</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.', array('@url' => 'http://php.net/manual/function.date.php')), |
|
71 |
'#default_value' => isset($this->options['second_date_format_custom']) ? $this->options['second_date_format_custom'] : '', |
|
72 |
// We have to use states instead of ctools dependency because dependency |
|
73 |
// doesn't handle multiple conditions. |
|
74 |
'#states' => array( |
|
75 |
'visible' => array( |
|
76 |
'#edit-options-date-format' => array('value' => 'today time ago'), |
|
77 |
'#edit-options-second-date-format' => array('value' => 'custom'), |
|
78 |
), |
|
79 |
), |
|
80 |
// We have to use ctools dependency too because states doesn't add the |
|
81 |
// correct left margin to the element's wrapper. |
|
82 |
'#dependency' => array( |
|
83 |
// This condition is handled by form API's states. |
|
84 |
// 'edit-options-date-format' => array('today time ago'), |
|
85 |
'edit-options-second-date-format' => array('custom'), |
|
86 |
), |
|
87 |
); |
|
54 | 88 |
$form['timezone'] = array( |
55 | 89 |
'#type' => 'select', |
56 | 90 |
'#title' => t('Timezone'), |
... | ... | |
66 | 100 |
function render($values) { |
67 | 101 |
$value = $this->get_value($values); |
68 | 102 |
$format = $this->options['date_format']; |
69 |
if (in_array($format, array('custom', 'raw time ago', 'time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span'))) { |
|
103 |
if (in_array($format, array('custom', 'raw time ago', 'time ago', 'today time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span'))) {
|
|
70 | 104 |
$custom_format = $this->options['custom_date_format']; |
71 | 105 |
} |
72 | 106 |
|
... | ... | |
78 | 112 |
return format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2); |
79 | 113 |
case 'time ago': |
80 | 114 |
return t('%time ago', array('%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2))); |
115 |
case 'today time ago': |
|
116 |
$second_format = $this->options['second_date_format']; |
|
117 |
$second_custom_format = $this->options['second_date_format_custom']; |
|
118 |
if (format_date(REQUEST_TIME, 'custom', 'Y-m-d', $timezone) == format_date($value, 'custom', 'Y-m-d', $timezone)) { |
|
119 |
return t('%time ago', array('%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2))); |
|
120 |
} |
|
121 |
elseif ($second_format == 'custom') { |
|
122 |
if ($second_custom_format == 'r') { |
|
123 |
return format_date($value, $second_format, $second_custom_format, $timezone, 'en'); |
|
124 |
} |
|
125 |
return format_date($value, $second_format, $second_custom_format, $timezone); |
|
126 |
} |
|
127 |
else { |
|
128 |
return format_date($value, $this->options['second_date_format'], '', $timezone); |
|
129 |
} |
|
81 | 130 |
case 'raw time hence': |
82 | 131 |
return format_interval(-$time_diff, is_numeric($custom_format) ? $custom_format : 2); |
83 | 132 |
case 'time hence': |
Formats disponibles : Unified diff
Weekly update of contrib modules