--- C:\Program Files\XAMPP\htdocs\drupal\modules\flexinode\field_timestamp.inc	2006-04-23 19:21:24.000000000 -0500
+++ C:\Program Files\XAMPP\htdocs\drupal\modules\flexinode\field_timestamp2.inc	2006-04-23 19:20:58.000000000 -0500
@@ -18,23 +18,61 @@
 function flexinode_field_timestamp_db_sort_column($field) {
   return 'flexinode_'. $field->field_id .'.numeric_data';
 }
 
 function flexinode_field_timestamp_insert($field, $node) {
   $fieldname = 'flexinode_'. $field->field_id;
-  $stamp = flexinode_validate_date($node, $fieldname);
+  $stamp = flexinode_get_timestamp($node, $fieldname);
   db_query('INSERT INTO {flexinode_data} (nid, field_id, numeric_data) VALUES (%d, %d, %d)', $node->nid, $field->field_id, $stamp);
 }
 
 function flexinode_field_timestamp_format($field, $node, $brief = 0) {
   $fieldname = 'flexinode_'. $field->field_id;
   // when called from node_preview, $node->$fieldname == 1 and time values are in _year, _month, etc.
   // when called from node_view, $node->$fieldname contains a timestamp that can be formatted directly
-  return ($node->$fieldname <> 1) ? format_date($node->$fieldname) : format_date(flexinode_validate_date($node, $fieldname));
+  return ($node->$fieldname <> 1) ? format_date($node->$fieldname) : format_date(flexinode_get_timestamp($node, $fieldname));
 }
 
+function flexinode_field_timestamp_validate($field, $node) {
+  $fieldname = 'flexinode_'. $field->field_id;  
+  $year = $node->{$fieldname . '_year'};
+  $month = $node->{$fieldname . '_month'};
+  $day = $node->{$fieldname . '_day'};
+  $hour = $node->{$fieldname . '_hour'};
+  $minute = $node->{$fieldname . '_minute'};
+
+  if (!ctype_digit($year) || !( (($year >= 0) && ($year <= 99)) || (($year >= 1000) && ($year <= 9999)) ) ){
+    form_set_error($fieldname, t('Please enter a 2 or 4 digit year.'));
+  }
+  
+  if (($year > 37) && ($year < 70)) {   // common limitation for 32 bit systems, see: http://www.php.net/manual/en/function.mktime.php
+    form_set_error($fieldname, t('Years between 1938 and 1970 must be entered as 4 digit years.'));
+  }
+  
+  if (($year >= 1000) && (($year < 1901) || ($year > 2037)) ) { // common limitation for 32 bit systems, see: http://www.php.net/manual/en/function.mktime.php
+    form_set_error($fieldname, t('Year must be between 1901 and 2037.'));  
+  }  
+  
+  if (!ctype_digit($month) || !(($month >= 1) && ($month <= 12)) ){
+    form_set_error($fieldname, t('Please select a valid month.'));
+  }
+  
+  if (!ctype_digit($day) || !checkdate($month, $day, ($year <= 99) ? $year + 2000 : $year) ){   
+    // above test adds 2000 to all 2 digit years... not perfect for year >= 70, but close enough for validating leap year
+    form_set_error($fieldname, t('Day is invalid for month and year entered.'));
+  }
+  
+  if (!ctype_digit($hour) || !(($hour >= 0) && ($hour <= 23)) ){
+    form_set_error($fieldname, t('Please select a valid hour.'));
+  }
+  
+  if (!ctype_digit($minute) || !(($minute >= 0) && ($minute <= 59)) ){
+    form_set_error($fieldname, t('Please select a valid minute.'));
+  }    
+}
+
 /**
  * A copy of event_form_date().
  */
 function flexinode_form_date($timestamp, $field) {
   $prefix = 'flexinode_'. $field->field_id;
 
@@ -127,13 +165,13 @@
   $form[$prefix]['#value'] = 1;
 
   return $form;
 }
 
 
-function flexinode_validate_date(&$node, $prefix = '') {
+function flexinode_get_timestamp(&$node, $prefix = '') {
   if (isset($node->{$prefix . '_year'}) && isset($node->{$prefix . '_month'}) && isset($node->{$prefix . '_day'}) && isset($node->{$prefix . '_hour'}) && isset($node->{$prefix . '_minute'})) {
     $hour = $node->{$prefix . '_hour'};
     if (variable_get('event_ampm', '0')) {
       if ($node->{$prefix . '_ampm'} == 'pm') {
         $hour += 12;
       }
