[dovecot-cvs]
dovecot/src/lib-imap imap-date.c,1.6,1.7 imap-date.h,1.2,1.3
cras at procontrol.fi
cras at procontrol.fi
Mon Sep 8 04:57:38 EEST 2003
Update of /home/cvs/dovecot/src/lib-imap
In directory danu:/tmp/cvs-serv19689/lib-imap
Modified Files:
imap-date.c imap-date.h
Log Message:
imap_to_datetime_offset() isn't needed. optimized imap_to_datetime() a bit.
Index: imap-date.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-date.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- imap-date.c 22 Apr 2003 17:47:59 -0000 1.6
+++ imap-date.c 8 Sep 2003 00:57:36 -0000 1.7
@@ -134,38 +134,56 @@
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] = ' ';
-const char *imap_to_datetime(time_t time)
-{
- struct tm *tm;
+ /* 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] = ' ';
- tm = localtime(&time);
- return imap_to_datetime_internal(tm, utc_offset(tm, time));
+ /* 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';
+
+ return buf;
}
Index: imap-date.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-date.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- imap-date.h 24 Oct 2002 00:15:38 -0000 1.2
+++ imap-date.h 8 Sep 2003 00:57:36 -0000 1.3
@@ -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);
More information about the dovecot-cvs
mailing list