--- nagios-2.0b5.original/cgi/cmd.c	2005-02-02 18:51:20.000000000 +0000
+++ nagios-2.0b5/cgi/cmd.c	2005-11-23 21:10:46.342910309 +0000
@@ -47,6 +47,7 @@
 extern scheduled_downtime *scheduled_downtime_list;
 extern comment *comment_list;
 
+extern int date_format;
 
 
 #define MAX_AUTHOR_LENGTH	64
@@ -62,6 +63,8 @@
 char *service_desc="";
 char *comment_author="";
 char *comment_data="";
+char *start_time_string="";
+char *end_time_string="";
 
 unsigned long comment_id=0;
 unsigned long downtime_id=0;
@@ -103,7 +106,6 @@
 void document_footer(void);
 int process_cgivars(void);
 
-int time_to_string(time_t *,char *,int);
 int string_to_time(char *,time_t *);
 
 
@@ -141,6 +143,14 @@
 		return ERROR;
 	        }
 
+	/* This requires the date_format parameter in the main config file */
+	if (strcmp(start_time_string,""))
+		string_to_time(start_time_string,&start_time);
+
+	if (strcmp(end_time_string,""))
+		string_to_time(end_time_string,&end_time);
+
+
 	/* read all object configuration data */
 	result=read_all_object_configuration_data(main_config_file,READ_ALL_OBJECT_DATA);
 	if(result==ERROR){
@@ -588,7 +598,11 @@
 				break;
 			        }
 
-			string_to_time(variables[x],&start_time);
+			start_time_string=(char *)malloc(strlen(variables[x])+1);
+			if(start_time_string==NULL)
+				start_time_string="";
+			else
+				strcpy(start_time_string,variables[x]);
 		        }
 
 		/* we found the end time */
@@ -599,7 +613,11 @@
 				break;
 			        }
 
-			string_to_time(variables[x],&end_time);
+			end_time_string=(char *)malloc(strlen(variables[x])+1);
+			if(end_time_string==NULL)
+				end_time_string="";
+			else
+				strcpy(end_time_string,variables[x]);
 		        }
 
 		/* we found the content type argument */
@@ -998,7 +1016,7 @@
 			printf("</b></td></tr>\n");
 		        }
 		time(&t);
-		time_to_string(&t,buffer,sizeof(buffer)-1);
+		get_time_string(&t,buffer,sizeof(buffer)-1,SHORT_DATE_TIME);
 		printf("<tr><td CLASS='optBoxRequiredItem'>Check Time:</td><td><b>");
 		printf("<INPUT TYPE='TEXT' NAME='start_time' VALUE='%s'>",buffer);
 		printf("</b></td></tr>\n");
@@ -1170,12 +1188,12 @@
 		printf("<tr><td CLASS='optBoxItem'><br></td></tr>\n");
 
 		time(&t);
-		time_to_string(&t,buffer,sizeof(buffer)-1);
+		get_time_string(&t,buffer,sizeof(buffer)-1,SHORT_DATE_TIME);
 		printf("<tr><td CLASS='optBoxRequiredItem'>Start Time:</td><td><b>");
 		printf("<INPUT TYPE='TEXT' NAME='start_time' VALUE='%s'>",buffer);
 		printf("</b></td></tr>\n");
 		t+=(unsigned long)7200;
-		time_to_string(&t,buffer,sizeof(buffer)-1);
+		get_time_string(&t,buffer,sizeof(buffer)-1,SHORT_DATE_TIME);
 		printf("<tr><td CLASS='optBoxRequiredItem'>End Time:</td><td><b>");
 		printf("<INPUT TYPE='TEXT' NAME='end_time' VALUE='%s'>",buffer);
 		printf("</b></td></tr>\n");
@@ -1273,12 +1291,12 @@
 		printf("<INPUT TYPE='TEXT' NAME='com_data' VALUE='%s' SIZE=40>",comment_data);
 		printf("</b></td></tr>\n");
 		time(&t);
-		time_to_string(&t,buffer,sizeof(buffer)-1);
+		get_time_string(&t,buffer,sizeof(buffer)-1,SHORT_DATE_TIME);
 		printf("<tr><td CLASS='optBoxRequiredItem'>Start Time:</td><td><b>");
 		printf("<INPUT TYPE='TEXT' NAME='start_time' VALUE='%s'>",buffer);
 		printf("</b></td></tr>\n");
 		t+=(unsigned long)7200;
-		time_to_string(&t,buffer,sizeof(buffer)-1);
+		get_time_string(&t,buffer,sizeof(buffer)-1,SHORT_DATE_TIME);
 		printf("<tr><td CLASS='optBoxRequiredItem'>End Time:</td><td><b>");
 		printf("<INPUT TYPE='TEXT' NAME='end_time' VALUE='%s'>",buffer);
 		printf("</b></td></tr>\n");
@@ -2611,19 +2629,7 @@
 
 
 
-/* converts a UNIX timestamp to a string we can use */
-int time_to_string(time_t *t, char *buffer, int buffer_length){
-	struct tm *lt;
-
-	lt=localtime(t);
-	snprintf(buffer,buffer_length-1,"%02d/%02d/%04d %02d:%02d:%02d",lt->tm_mon+1,lt->tm_mday,lt->tm_year+1900,lt->tm_hour,lt->tm_min,lt->tm_sec);
-	buffer[buffer_length-1]='\x0';
-
-	return OK;
-        }
-
-
-/* converts a time string to a UNIX timestamp */
+/* converts a time string to a UNIX timestamp, respecting the date_format option */
 int string_to_time(char *buffer, time_t *t){
 	struct tm lt;
 
@@ -2642,7 +2648,12 @@
 	lt.tm_wday=0;
 	lt.tm_yday=0;
 
-	sscanf(buffer,"%02d/%02d/%04d %02d:%02d:%02d",&lt.tm_mon,&lt.tm_mday,&lt.tm_year,&lt.tm_hour,&lt.tm_min,&lt.tm_sec);
+	if(date_format==DATE_FORMAT_EURO)
+		sscanf(buffer,"%02d-%02d-%04d %02d:%02d:%02d",&lt.tm_mday,&lt.tm_mon,&lt.tm_year,&lt.tm_hour,&lt.tm_min,&lt.tm_sec);
+	else if(date_format==DATE_FORMAT_ISO8601 || date_format==DATE_FORMAT_STRICT_ISO8601)
+		sscanf(buffer,"%04d-%02d-%02d%*[ T]%02d:%02d:%02d",&lt.tm_year,&lt.tm_mon,&lt.tm_mday,&lt.tm_hour,&lt.tm_min,&lt.tm_sec);
+	else
+		sscanf(buffer,"%02d-%02d-%04d %02d:%02d:%02d",&lt.tm_mon,&lt.tm_mday,&lt.tm_year,&lt.tm_hour,&lt.tm_min,&lt.tm_sec);
 
 	lt.tm_mon--;
 	lt.tm_year-=1900;
