datetime doesn't work with CCK

kenorb - December 8, 2008 - 16:17
Project:Resource Conflict
Version:6.x-2.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

What's about support for date time field?
There is:

        elseif ($field['type'] == 'date' && $field['todate'] == 'required' && $field['required']) {
          $date_fields[$field['field_name']] = $field['widget']['label'];
        }

My solution:

        elseif (($field['type'] == 'date' || $field['type'] == 'datetime') && $field['todate'] == 'required' && $field['required']) {
          $date_fields[$field['field_name']] = $field['widget']['label'];
        }

But I didn't test it if it will work.

#1

kenorb - July 23, 2009 - 15:58
Version:5.x-2.x-dev» 6.x-2.x-dev

#2

pdcarto - August 29, 2009 - 19:29

Are there any plans to address this feature request?

#3

pdcarto - August 29, 2009 - 19:57

I would expand this feature request as follows:

Support all date field types. RC should not fail to work just because a content type doesn't use its preferred date field type.

#4

redben - October 17, 2009 - 11:43
Priority:normal» critical

I would have expected this behaviour (not supporting datetime) I too think it is a must have.
So +1

#5

redben - October 17, 2009 - 12:30
Version:6.x-2.x-dev» 6.x-2.0
Status:active» needs review

I have made a patch to resource_conflict.module including the code from knorb and changed _resource_conflict_overlaps_from_date tp support date_make_date from DATE_DATETIME format. It is my first contributed patch, if there is a problem please tell me and i'll correct it. Note that the patch has been made against version 2.0

@@ -147,7 +147,7 @@ function resource_conflict_form_alter(&$
         if ($field['type'] == 'nodereference') {
           $nodereference_fields[$field['field_name']] = $field['widget']['labe$
         }
-        elseif ($field['type'] == 'date' && $field['todate'] == 'required' && $
+        elseif (($field['type'] == 'date' || $field['type'] == 'datetime') && $
           $date_fields[$field['field_name']] = $field['widget']['label'];
         }
       }
@@ -326,8 +326,13 @@ function _resource_conflict_get_node_res
  *   An array of node ID's
  */
function _resource_conflict_overlaps_from_date($date_start, $date_end) {
-  $start = date_make_date($date_start, 'GMT', DATE_ISO);
-  $end = date_make_date($date_end, 'GMT', DATE_ISO);
+  // make default type to DATE_ISO
+  $type = DATE_ISO;
+  // if date_start is not in DATE_ISO set type to DATE_DATETIME
+  if (!date_is_valid($date_start,DATE_ISO)) $type = DATE_DATETIME;
+
+  $start = date_make_date($date_start, 'GMT', $type);
+  $end = date_make_date($date_end, 'GMT', $type);
   return _resource_conflict_get_overlaps($start, $end);
}

AttachmentSize
resource_conflict.module.datetime.patch 1.28 KB

#6

redben - October 17, 2009 - 12:30

Forgot to mention that i tested it with my datetime field and it worked as expected :-)

#7

deviantintegral - October 17, 2009 - 16:15
Version:6.x-2.0» 6.x-2.x-dev
Priority:critical» normal
Status:needs review» needs work

Thanks redben for the patch. A few notes:

  • Critical is for issues where things actually break, not for new features
  • Always roll patches against the latest -dev version, though in this case it should be OK as they are nearly identical.
  • Single line comments should start with a capital and end with a period.
  • The if statement should be on two lines.

Otherwise, it looks good - it'd be great if someone else tested this too.

 
 

Drupal is a registered trademark of Dries Buytaert.