* Miscellaneous functions which handle calendar components.
*/
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <limits.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <string.h>
-#include <pwd.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <pthread.h>
-#include <signal.h>
-#include <time.h>
#include "webcit.h"
#include "webserver.h"
struct tm tm;
const int span = 10;
int all_day_event = 0;
+ char calhourformat[16];
+
+ get_preference("calhourformat", calhourformat, sizeof calhourformat);
now = time(NULL);
localtime_r(&now, &tm_now);
wprintf("Hour: ");
wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
for (i=0; i<=23; ++i) {
- wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
- ((tm.tm_hour == i) ? "SELECTED" : ""),
- i, hourname[i]
- );
+
+ if (!strcasecmp(calhourformat, "24")) {
+ wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
+ ((tm.tm_hour == i) ? "SELECTED" : ""),
+ i, i
+ );
+ }
+ else {
+ wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
+ ((tm.tm_hour == i) ? "SELECTED" : ""),
+ i, hourname[i]
+ );
+ }
+
}
wprintf("</SELECT>\n");
}
-struct icaltimetype icaltime_from_webform(char *prefix) {
- struct icaltimetype t;
- time_t tt;
- struct tm tm;
- char vname[SIZ];
+void icaltime_from_webform(struct icaltimetype *t, char *prefix) {
+ char vname[32];
+ time_t tt;
+ struct tm tm;
+ struct icaltimetype t2;
+
+ tt = time(NULL);
+ localtime_r(&tt, &tm);
+
+ sprintf(vname, "%s_month", prefix); tm.tm_mon = atoi(bstr(vname)) - 1;
+ sprintf(vname, "%s_day", prefix); tm.tm_mday = atoi(bstr(vname));
+ sprintf(vname, "%s_year", prefix); tm.tm_year = atoi(bstr(vname)) - 1900;
+ sprintf(vname, "%s_hour", prefix); tm.tm_hour = atoi(bstr(vname));
+ sprintf(vname, "%s_minute", prefix); tm.tm_min = atoi(bstr(vname));
+
+ tt = mktime(&tm);
+ t2 = icaltime_from_timet(tt, 0);
+ memcpy(t, &t2, sizeof(struct icaltimetype));
+}
+
- tt = time(NULL);
- localtime_r(&tt, &tm);
+void icaltime_from_webform_dateonly(struct icaltimetype *t, char *prefix) {
+ char vname[32];
- sprintf(vname, "%s_month", prefix); tm.tm_mon = atoi(bstr(vname)) - 1;
- sprintf(vname, "%s_day", prefix); tm.tm_mday = atoi(bstr(vname));
- sprintf(vname, "%s_year", prefix); tm.tm_year = atoi(bstr(vname)) - 1900;
- sprintf(vname, "%s_hour", prefix); tm.tm_hour = atoi(bstr(vname));
- sprintf(vname, "%s_minute", prefix); tm.tm_min = atoi(bstr(vname));
+ memset(t, 0, sizeof(struct icaltimetype));
- tt = mktime(&tm);
- t = icaltime_from_timet(tt, 0);
- t = icaltime_normalize(t);
- return(t);
+ sprintf(vname, "%s_month", prefix); t->month = atoi(bstr(vname));
+ sprintf(vname, "%s_day", prefix); t->day = atoi(bstr(vname));
+ sprintf(vname, "%s_year", prefix); t->year = atoi(bstr(vname));
+ t->is_utc = 1;
+ t->is_date = 1;
}