]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap_to_datetime_offset() isn't needed. optimized imap_to_datetime() a bit.
authorTimo Sirainen <tss@iki.fi>
Mon, 8 Sep 2003 00:57:36 +0000 (03:57 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 8 Sep 2003 00:57:36 +0000 (03:57 +0300)
--HG--
branch : HEAD

src/lib-imap/imap-date.c
src/lib-imap/imap-date.h

index 5ebe74fbf7176c5336909a94003e9c8b07ae77c0..fbbfa5fcd756d3c610fb7dff25f96df244d256b3 100644 (file)
@@ -134,38 +134,56 @@ int imap_parse_datetime(const char *str, time_t *time, int *timezone_offset)
        return TRUE;
 }
 
-static const char *imap_to_datetime_internal(struct tm *tm, int timezone_offset)
+const char *imap_to_datetime(time_t time)
 {
-       int negative;
+       char *buf;
+       struct tm *tm;
+       int timezone_offset, year;
 
-       if (timezone_offset >= 0)
-               negative = 0;
-       else {
-               negative = 1;
-               timezone_offset = -timezone_offset;
-       }
+       tm = localtime(&time);
+       timezone_offset = utc_offset(tm, time);
 
-       return t_strdup_printf("%02d-%s-%04d %02d:%02d:%02d %c%02d%02d",
-                              tm->tm_mday, month_names[tm->tm_mon],
-                              tm->tm_year+1900,
-                              tm->tm_hour, tm->tm_min, tm->tm_sec,
-                              negative ? '-' : '+',
-                              timezone_offset / 60, timezone_offset % 60);
-}
+       /* @UNSAFE: but faster than t_strdup_printf() call.. */
+       buf = t_malloc(27);
 
-const char *imap_to_datetime_offset(time_t time, int timezone_offset)
-{
-       struct tm *tm;
+       /* dd-mon- */
+       buf[0] = (tm->tm_mday / 10) + '0';
+       buf[1] = (tm->tm_mday % 10) + '0';
+       buf[2] = '-';
+       memcpy(buf+3, month_names[tm->tm_mon], 3);
+       buf[6] = '-';
 
-       time += timezone_offset;
-       tm = gmtime(&time);
-       return imap_to_datetime_internal(tm, timezone_offset);
-}
+       /* yyyy */
+       year = tm->tm_year + 1900;
+       buf[7] = (year / 1000) + '0';
+       buf[8] = ((year / 100) % 10) + '0';
+       buf[9] = ((year / 10) % 10) + '0';
+       buf[10] = (year % 10) + '0';
+       buf[11] = ' ';
+
+       /* hh:mi:ss */
+       buf[12] = (tm->tm_hour / 10) + '0';
+       buf[13] = (tm->tm_hour % 10) + '0';
+       buf[14] = ':';
+       buf[15] = (tm->tm_min / 10) + '0';
+       buf[16] = (tm->tm_min % 10) + '0';
+       buf[17] = ':';
+       buf[18] = (tm->tm_sec / 10) + '0';
+       buf[19] = (tm->tm_sec % 10) + '0';
+       buf[20] = ' ';
 
-const char *imap_to_datetime(time_t time)
-{
-       struct tm *tm;
+       /* timezone */
+       if (timezone_offset >= 0)
+               buf[21] = '+';
+       else {
+               buf[21] = '-';
+               timezone_offset = -timezone_offset;
+       }
+       buf[22] = (timezone_offset / 600) + '0';
+       buf[23] = ((timezone_offset / 60) % 10) + '0';
+       buf[24] = ((timezone_offset % 60) / 10) + '0';
+       buf[25] = (timezone_offset % 10) + '0';
+       buf[26] = '\0';
 
-       tm = localtime(&time);
-       return imap_to_datetime_internal(tm, utc_offset(tm, time));
+       return buf;
 }
index b7871a973080cc2afb0f2e3b8d170f39ca7a1465..03604027ac71fd18e67a6ff74fb545b2c92d92bb 100644 (file)
@@ -7,8 +7,6 @@
 int imap_parse_date(const char *str, time_t *time);
 int imap_parse_datetime(const char *str, time_t *time, int *timezone_offset);
 
-/* Returns given UTC time in given timezone. */
-const char *imap_to_datetime_offset(time_t time, int timezone_offset);
 /* Returns given UTC time in local timezone. */
 const char *imap_to_datetime(time_t time);