From: Timo Sirainen Date: Mon, 8 Sep 2003 00:57:36 +0000 (+0300) Subject: imap_to_datetime_offset() isn't needed. optimized imap_to_datetime() a bit. X-Git-Tag: 1.1.alpha1~4345 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd84e8cf0bfeba1ed3e562b8090478c9558911f5;p=thirdparty%2Fdovecot%2Fcore.git imap_to_datetime_offset() isn't needed. optimized imap_to_datetime() a bit. --HG-- branch : HEAD --- diff --git a/src/lib-imap/imap-date.c b/src/lib-imap/imap-date.c index 5ebe74fbf7..fbbfa5fcd7 100644 --- a/src/lib-imap/imap-date.c +++ b/src/lib-imap/imap-date.c @@ -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; } diff --git a/src/lib-imap/imap-date.h b/src/lib-imap/imap-date.h index b7871a9730..03604027ac 100644 --- a/src/lib-imap/imap-date.h +++ b/src/lib-imap/imap-date.h @@ -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);