]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar_tools.c
* In the calendar code, changed all "struct tm *" to "struct tm" and changed
[citadel.git] / webcit / calendar_tools.c
index 7ece52fda877a5f9f11438d67d122b273a486c98..9426716b355a21eb21bb8e74f8947c9d775a8703 100644 (file)
@@ -36,6 +36,13 @@ char *days[] = {
        "Thursday", "Friday", "Saturday"
 };
 
+char *hourname[] = {
+       "12am", "1am", "2am", "3am", "4am", "5am", "6am",
+       "7am", "8am", "9am", "10am", "11am", "12pm",
+       "1pm", "2pm", "3pm", "4pm", "5pm", "6pm",
+       "7pm", "8pm", "9pm", "10pm", "11pm"
+};
+
 #ifdef HAVE_ICAL_H
 
 /*
@@ -60,27 +67,27 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        int i;
 
        time_t now;
-       struct tm *tm_now;
+       struct tm tm_now;
        int this_year;
 
        time_t tt;
-       struct tm *tm;
+       struct tm tm;
 
        const int span = 10;
 
        now = time(NULL);
-       tm_now = localtime(&now);
-       this_year = tm_now->tm_year + 1900;
+       memcpy(&tm_now, localtime(&now), sizeof(struct tm));
+       this_year = tm_now.tm_year + 1900;
 
        if (t == NULL) return;
        tt = icaltime_as_timet(*t);
-       tm = localtime(&tt);
+       memcpy(&tm, localtime(&tt), sizeof(struct tm));
 
        wprintf("Month: ");
        wprintf("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
        for (i=0; i<=11; ++i) {
                wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
-                       ((tm->tm_mon == i) ? "SELECTED" : ""),
+                       ((tm.tm_mon == i) ? "SELECTED" : ""),
                        i+1,
                        months[i]
                );
@@ -91,7 +98,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
        for (i=1; i<=31; ++i) {
                wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
-                       ((tm->tm_mday == i) ? "SELECTED" : ""),
+                       ((tm.tm_mday == i) ? "SELECTED" : ""),
                        i, i
                );
        }
@@ -118,9 +125,9 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        wprintf("Hour: ");
        wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
        for (i=0; i<=23; ++i) {
-               wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
-                       ((tm->tm_hour == i) ? "SELECTED" : ""),
-                       i, i
+               wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
+                       ((tm.tm_hour == i) ? "SELECTED" : ""),
+                       i, hourname[i]
                );
        }
        wprintf("</SELECT>\n");
@@ -128,8 +135,8 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        wprintf("Minute: ");
        wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
        for (i=0; i<=59; ++i) {
-               wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
-                       ((tm->tm_min == i) ? "SELECTED" : ""),
+               wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
+                       ((tm.tm_min == i) ? "SELECTED" : ""),
                        i, i
                );
        }