]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar_tools.c
* fetching the 12/24 Hours switch from config over and over is expansive. (gprof...
[citadel.git] / webcit / calendar_tools.c
index 58e62146f4515055f2e0c60b71107f048be19d06..edb17de924caf8ce698331de81e47f5e36331894 100644 (file)
@@ -49,9 +49,12 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        struct tm tm;
        const int span = 10;
        int all_day_event = 0;
-       char calhourformat[16];
-
-       get_preference("calhourformat", calhourformat, sizeof calhourformat);
+       time_t monthselect_time;
+       struct tm monthselect_tm;
+       char monthselect_str[32];
+       int time_format;
+       
+       time_format = get_time_format_cached ();
 
        now = time(NULL);
        localtime_r(&now, &tm_now);
@@ -70,10 +73,13 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        wprintf(_("Month: "));
        wprintf("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
        for (i=0; i<=11; ++i) {
+               monthselect_time = 1137997451 + (i * 2592000);
+               localtime_r(&monthselect_time, &monthselect_tm);
+               wc_strftime(monthselect_str, sizeof monthselect_str, "%B", &monthselect_tm);
                wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
                        ((tm.tm_mon == i) ? "SELECTED" : ""),
                        i+1,
-                       monthname(i)
+                       monthselect_str
                );
        }
        wprintf("</SELECT>\n");
@@ -110,7 +116,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
        for (i=0; i<=23; ++i) {
 
-               if (!strcasecmp(calhourformat, "24")) {
+       if (time_format == WC_TIMEFORMAT_24) {
                        wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
                                ((tm.tm_hour == i) ? "SELECTED" : ""),
                                i, i
@@ -147,24 +153,22 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
  */
 void icaltime_from_webform(struct icaltimetype *t, char *prefix) {
        char vname[32];
-        time_t tt;
-        struct tm tm;
        struct icaltimetype t2;
+       char timestr[32];
+       int month, mday, year, hour, minute;
 
-        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));
+        sprintf(vname, "%s_month", prefix);     month = atoi(bstr(vname));
+        sprintf(vname, "%s_day", prefix);       mday = atoi(bstr(vname));
+        sprintf(vname, "%s_year", prefix);      year = atoi(bstr(vname));
+        sprintf(vname, "%s_hour", prefix);      hour = atoi(bstr(vname));
+        sprintf(vname, "%s_minute", prefix);    minute = atoi(bstr(vname));
 
-        tt = mktime(&tm);
-        t2 = icaltime_from_timet(tt, 0);
+       sprintf(timestr, "%04d%02d%02dT%02d%02d00", year, month, mday, hour, minute);
+        t2 = icaltime_from_string(timestr);
        memcpy(t, &t2, sizeof(struct icaltimetype));
 }
 
+
 /**
  *\brief Get time from form
  * get the time back from the user and convert it into internal structs.