Index: handlers/views_handler_field_date.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/handlers/views_handler_field_date.inc,v
retrieving revision 1.2.2.2
diff -u -p -r1.2.2.2 views_handler_field_date.inc
--- handlers/views_handler_field_date.inc 13 Aug 2010 22:27:20 -0000 1.2.2.2
+++ handlers/views_handler_field_date.inc 24 Aug 2010 22:56:20 -0000
@@ -23,14 +23,10 @@ class views_handler_field_date extends v
'#type' => 'select',
'#title' => t('Date format'),
'#options' => array(
- 'small' => format_date($time, 'small'),
- 'medium' => format_date($time, 'medium'),
- 'large' => format_date($time, 'large'),
+ 'small' => format_date($time, 'custom', 'm/d/Y'),
+ 'medium' => format_date($time, 'custom', 'D, m/d/Y'),
+ 'large' => format_date($time, 'custom', 'l, F j, Y'),
'custom' => t('Custom'),
- 'raw time ago' => t('Time ago'),
- 'time ago' => t('Time ago (with "ago" appended)'),
- 'raw time span' => t('Time span (future dates start with - )'),
- 'time span' => t('Time span (with "ago/hence" appended)'),
),
'#default_value' => isset($this->options['date_format']) ? $this->options['date_format'] : 'small',
);
@@ -40,38 +36,54 @@ class views_handler_field_date extends v
'#description' => t('If "Custom", see the PHP docs for date formats. If "Time ago" this is the the number of different units to display, which defaults to two.'),
'#default_value' => isset($this->options['custom_date_format']) ? $this->options['custom_date_format'] : '',
'#process' => array('views_process_dependency'),
- '#dependency' => array('edit-options-date-format' => array('custom', 'raw time ago', 'time ago', 'raw time span', 'time span')),
+ '#dependency' => array('edit-options-date-format' => array('custom')),
);
}
function render($values) {
$value = $values->{$this->field_alias};
$format = $this->options['date_format'];
- if (in_array($format, array('custom', 'raw time ago', 'time ago', 'raw time span', 'time span'))) {
+ if (in_array($format, array('custom'))) {
$custom_format = $this->options['custom_date_format'];
}
-
+
+ // TODO
+ // Set timezone offset here.
+ $timezone = NULL;
+
+ // TODO
+ // Set timezone offset here.
+ //$date = new DateTime($value, $timezone);
+ $date = date_create($value);
+
+ // Empty field. Render as text.
if (!$value) {
return theme('views_nodate');
}
+
+ // Check that date_create() returned a valid $date object.
+ // Set error message if not and render as text.
+ elseif (!$date) {
+ drupal_set_message(t("Invalide date field, '" . $this->options['field'] . "', should be of data type date."), 'error', FALSE);
+ return theme('views_nodate');
+ }
else {
- $time_diff = time() - $value; // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
switch ($format) {
- case 'raw time ago':
- return format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2);
- case 'time ago':
- return t('%time ago', array('%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2)));
- case 'raw time span':
- return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2);
- case 'time span':
- return t(($time_diff < 0 ? '%time hence' : '%time ago'), array('%time' => format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2)));
case 'custom':
+ // TODO probably do not need this if statement
if ($custom_format == 'r') {
- return format_date($value, $format, $custom_format, null, 'en');
+ return date_format($date, $custom_format);
}
- return format_date($value, $format, $custom_format);
+ // Return custom formated date value.
+ return date_format($date, $custom_format);
+ case 'medium':
+ return date_format($date, 'D, m/d/Y');
+ case 'large':
+ return date_format($date, 'l, F j, Y');
+ case 'small':
default:
- return format_date($value, $format);
+ // Return default formated date value.
+ return date_format($date, 'm/d/Y');
}
}
}
Index: handlers/views_handler_field_datetime.inc
===================================================================
RCS file: handlers/views_handler_field_datetime.inc
diff -N handlers/views_handler_field_datetime.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ handlers/views_handler_field_datetime.inc 24 Aug 2010 22:56:20 -0000
@@ -0,0 +1,102 @@
+ 'small');
+ $options['custom_date_format'] = array('default' => '');
+
+ return $options;
+ }
+
+ function options_form(&$form, &$form_state) {
+ parent::options_form($form, $form_state);
+ $time = time();
+
+ $form['date_format'] = array(
+ '#type' => 'select',
+ '#title' => t('Date format'),
+ '#options' => array(
+ 'small' => format_date($time, 'small'),
+ 'medium' => format_date($time, 'medium'),
+ 'large' => format_date($time, 'large'),
+ 'custom' => t('Custom'),
+ 'raw time ago' => t('Time ago'),
+ 'time ago' => t('Time ago (with "ago" appended)'),
+ 'raw time span' => t('Time span (future dates start with - )'),
+ 'time span' => t('Time span (with "ago/hence" appended)'),
+ ),
+ '#default_value' => isset($this->options['date_format']) ? $this->options['date_format'] : 'small',
+ );
+ $form['custom_date_format'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Custom date format'),
+ '#description' => t('If "Custom", see the PHP docs for date formats. If "Time ago" this is the the number of different units to display, which defaults to two.'),
+ '#default_value' => isset($this->options['custom_date_format']) ? $this->options['custom_date_format'] : '',
+ '#process' => array('views_process_dependency'),
+ '#dependency' => array('edit-options-date-format' => array('custom', 'raw time ago', 'time ago', 'raw time span', 'time span')),
+ );
+ }
+
+ function render($values) {
+ $value = $values->{$this->field_alias};
+ $format = $this->options['date_format'];
+ if (in_array($format, array('custom', 'raw time ago', 'time ago', 'raw time span', 'time span'))) {
+ $custom_format = $this->options['custom_date_format'];
+ }
+
+ // TODO
+ // Set timezone offset here.
+ $timezone = NULL;
+
+ // TODO
+ // Set timezone offset here.
+ //$date = new DateTime($value, $timezone);
+ $date = date_create($value);
+
+ if (!$value) {
+ return theme('views_nodate');
+ }
+ // Check that date_create() returned a valid $date object.
+ // Set error message if not and render as text.
+ elseif (!$date) {
+ drupal_set_message(t("Invalide date field, '" . $this->options['field'] . "', should be of data type datetime."), 'error', FALSE);
+ return theme('views_nodate');
+ }
+ else {
+ // TODO Add $timezone offset if needed.
+ $time_diff = time() - strtotime($value); // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
+ switch ($format) {
+ case 'raw time ago':
+ return format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2);
+ case 'time ago':
+ return t('%time ago', array('%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2)));
+ case 'raw time span':
+ return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2);
+ case 'time span':
+ return t(($time_diff < 0 ? '%time hence' : '%time ago'), array('%time' => format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2)));
+ case 'custom':
+ // TODO probably do not need this if statement
+ if ($custom_format == 'r') {
+ return date_format($date, $custom_format);
+ }
+ // Return custom formated date value.
+ return date_format($date, $custom_format);
+ case 'medium':
+ return date_format($date, 'D, m/d/Y - H:i');
+ case 'large':
+ return date_format($date, 'l, F j, Y - H:i');
+ case 'small':
+ default:
+ // Return default formated date value.
+ return date_format($date, 'm/d/Y - H:i');
+ }
+ }
+ }
+}
Index: handlers/views_handler_field_timestamp.inc
===================================================================
RCS file: handlers/views_handler_field_timestamp.inc
diff -N handlers/views_handler_field_timestamp.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ handlers/views_handler_field_timestamp.inc 24 Aug 2010 22:56:20 -0000
@@ -0,0 +1,83 @@
+ 'small');
+
+ return $options;
+ }
+
+ function options_form(&$form, &$form_state) {
+ parent::options_form($form, $form_state);
+ $time = time();
+
+ $form['date_format'] = array(
+ '#type' => 'select',
+ '#title' => t('Date format'),
+ '#options' => array(
+ 'small' => format_date($time, 'small'),
+ 'medium' => format_date($time, 'medium'),
+ 'large' => format_date($time, 'large'),
+ 'custom' => t('Custom'),
+ 'raw time ago' => t('Time ago'),
+ 'time ago' => t('Time ago (with "ago" appended)'),
+ 'raw time span' => t('Time span (future dates start with - )'),
+ 'time span' => t('Time span (with "ago/hence" appended)'),
+ ),
+ '#default_value' => isset($this->options['date_format']) ? $this->options['date_format'] : 'small',
+ );
+ $form['custom_date_format'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Custom date format'),
+ '#description' => t('If "Custom", see the PHP docs for date formats. If "Time ago" this is the the number of different units to display, which defaults to two.'),
+ '#default_value' => isset($this->options['custom_date_format']) ? $this->options['custom_date_format'] : '',
+ '#process' => array('views_process_dependency'),
+ '#dependency' => array('edit-options-date-format' => array('custom', 'raw time ago', 'time ago', 'raw time span', 'time span')),
+ );
+ }
+
+ function render($values) {
+ $value = $values->{$this->field_alias};
+ $format = $this->options['date_format'];
+ if (in_array($format, array('custom', 'raw time ago', 'time ago', 'raw time span', 'time span'))) {
+ $custom_format = $this->options['custom_date_format'];
+ }
+
+ if (!$value) {
+ return theme('views_nodate');
+ }
+ // Check that $value is numeric and can be converted with format_date.
+ // Set error message if not and render as text.
+ elseif (!is_numeric($value)) {
+ drupal_set_message(t("Invalide date field, '" . $this->options['field'] . "', should be a UNIX timestamp"), 'error', FALSE);
+ return theme('views_nodate');
+ }
+ else {
+ $time_diff = time() - $value; // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
+ switch ($format) {
+ case 'raw time ago':
+ return format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2);
+ case 'time ago':
+ return t('%time ago', array('%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2)));
+ case 'raw time span':
+ return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2);
+ case 'time span':
+ return t(($time_diff < 0 ? '%time hence' : '%time ago'), array('%time' => format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2)));
+ case 'custom':
+ if ($custom_format == 'r') {
+ return format_date($value, $format, $custom_format, null, 'en');
+ }
+ return format_date($value, $format, $custom_format);
+ default:
+ return format_date($value, $format);
+ }
+ }
+ }
+}
Index: includes/handlers.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/handlers.inc,v
retrieving revision 1.109.2.17
diff -u -p -r1.109.2.17 handlers.inc
--- includes/handlers.inc 30 Jun 2010 19:19:02 -0000 1.109.2.17
+++ includes/handlers.inc 24 Aug 2010 22:56:21 -0000
@@ -1212,6 +1212,12 @@ function views_views_handlers() {
'views_handler_field_date' => array(
'parent' => 'views_handler_field',
),
+ 'views_handler_field_datetime' => array(
+ 'parent' => 'views_handler_field_date',
+ ),
+ 'views_handler_field_timestamp' => array(
+ 'parent' => 'views_handler_field_date',
+ ),
'views_handler_field_boolean' => array(
'parent' => 'views_handler_field',
),