]> 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 d62cb8296907e4f39606297176ea92b3350e4675..edb17de924caf8ce698331de81e47f5e36331894 100644 (file)
@@ -52,9 +52,9 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        time_t monthselect_time;
        struct tm monthselect_tm;
        char monthselect_str[32];
-       char calhourformat[16];
-
-       get_preference("calhourformat", calhourformat, sizeof calhourformat);
+       int time_format;
+       
+       time_format = get_time_format_cached ();
 
        now = time(NULL);
        localtime_r(&now, &tm_now);
@@ -116,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
@@ -153,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.