From 11ebd35cdf53f877efb11ed1ce9ccb771d2a091c Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Thu, 16 Aug 2007 10:54:48 +0200 Subject: [PATCH] Remove the time module alltogether. Signed-off-by: Pierre Habouzit --- imap/util.c | 6 +- lib-lib/CMakeLists.txt | 1 - lib-lib/date.c | 188 ----------------------------------------- lib-lib/date.h | 27 ------ lib-lib/lib-lib.h | 1 - lib-mime/rfc822parse.c | 16 ++-- lib-mx/mbox.c | 5 +- pattern.c | 8 +- 8 files changed, 22 insertions(+), 230 deletions(-) delete mode 100644 lib-lib/date.c delete mode 100644 lib-lib/date.h diff --git a/imap/util.c b/imap/util.c index f4b60a7..b6ba310 100644 --- a/imap/util.c +++ b/imap/util.c @@ -254,16 +254,18 @@ char *imap_next_word (char *s) } /* imap_parse_date: date is of the form: DD-MMM-YYYY HH:MM:SS +ZZzz */ -time_t imap_parse_date (char *s) +time_t imap_parse_date(char *s) { struct tm tm; const char *loc; + time_t tz; p_clear(&tm, 1); loc = setlocale(LC_TIME, "C"); strptime(s, "%d-%b-%Y %T %z", &tm); + tz = tm.tm_gmtoff; setlocale(LC_TIME, loc); - return mutt_mktime(&tm, 1); + return timegm(&tm) + tz; } /* imap_qualify_path: make an absolute IMAP folder target, given IMAP_MBOX diff --git a/lib-lib/CMakeLists.txt b/lib-lib/CMakeLists.txt index 2a6e031..9fd6b89 100644 --- a/lib-lib/CMakeLists.txt +++ b/lib-lib/CMakeLists.txt @@ -2,7 +2,6 @@ ADD_LIBRARY(lib array.c bits.c buffer.c - date.c file.c hash.c list.c diff --git a/lib-lib/date.c b/lib-lib/date.c deleted file mode 100644 index 8fa90c6..0000000 --- a/lib-lib/date.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * Copyright © 2006 Pierre Habouzit - */ - -/* - * Copyright notice from original mutt: - * Copyright (C) 1996-2000 Michael R. Elkins - * - * This file is part of mutt-ng, see http://www.muttng.org/. - * It's licensed under the GNU General Public License, - * please see the file GPL in the top level source directory. - */ - -#include "lib-lib.h" - -/* returns the seconds east of UTC given `g' and its corresponding gmtime() - representation */ -static time_t compute_tz(time_t g, struct tm *utc) -{ - struct tm *lt = localtime (&g); - time_t t; - int yday; - - t = (lt->tm_hour - utc->tm_hour) * 3600 - + (lt->tm_min - utc->tm_min) * 60; - yday = (lt->tm_yday - utc->tm_yday); - - if (yday) { - /* This code is optimized to negative timezones (West of Greenwich) */ - if (yday == -1 || /* UTC passed midnight before localtime */ - yday > 1) /* UTC passed new year before localtime */ - t -= 24 * 60 * 60; - else - t += 24 * 60 * 60; - } - - return t; -} - -/* Returns the local timezone in seconds east of UTC for the time t, - or for the current time if t is zero. */ -time_t mutt_local_tz(time_t t) -{ - struct tm *ptm; - struct tm utc; - - if (!t) - t = time(NULL); - - /* need to make a copy because gmtime/localtime return a pointer to - static memory (grr!) */ - ptm = gmtime(&t); - utc = *ptm; - return compute_tz(t, &utc); -} - -/* converts struct tm to time_t, but does not take the local timezone into - account unless ``local'' is nonzero */ -time_t mutt_mktime(struct tm *t, int local) -{ - static short const AccumDaysPerMonth[12] = { - 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 - }; - - time_t g; - - /* Compute the number of days since January 1 in the same year */ - g = AccumDaysPerMonth[t->tm_mon % 12]; - - /* The leap years are 1972 and every 4. year until 2096, - * but this algoritm will fail after year 2099 */ - g += t->tm_mday; - if ((t->tm_year % 4) || t->tm_mon < 2) - g--; - t->tm_yday = g; - - /* Compute the number of days since January 1, 1970 */ - g += (t->tm_year - 70) * 365; - g += (t->tm_year - 69) / 4; - - /* Compute the number of hours */ - g *= 24; - g += t->tm_hour; - - /* Compute the number of minutes */ - g *= 60; - g += t->tm_min; - - /* Compute the number of seconds */ - g *= 60; - g += t->tm_sec; - - if (local) - g -= compute_tz(g, t); - - return g; -} - -/* Return 1 if month is February of leap year, else 0 */ -__attribute__((const)) -static int isLeapYearFeb(int m, int y) -{ - return (m == 1) /* february ? */ - && !(y & 3) /* multiple of 4 ? */ - && ((y % 100) || !((y + 1900) % 400)); - /* !multiple of 100, or multiple of 400 */ -} - -__attribute__((const)) -static inline int nbDaysInMonth(int m, int y) -{ - static char const DaysPerMonth[12] = { - 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 - }; - - return DaysPerMonth[m] + isLeapYearFeb(m, y); -} - -void mutt_normalize_time(struct tm *tm) -{ - while (tm->tm_sec < 0) { - tm->tm_sec += 60; - tm->tm_min--; - } - while (tm->tm_sec >= 60) { - tm->tm_sec -= 60; - tm->tm_min++; - } - while (tm->tm_min < 0) { - tm->tm_min += 60; - tm->tm_hour--; - } - while (tm->tm_min >= 60) { - tm->tm_min -= 60; - tm->tm_hour++; - } - while (tm->tm_hour < 0) { - tm->tm_hour += 24; - tm->tm_mday--; - } - while (tm->tm_hour >= 24) { - tm->tm_hour -= 24; - tm->tm_mday++; - } - /* use loops on NNNdwmy user input values? */ - while (tm->tm_mon < 0) { - tm->tm_mon += 12; - tm->tm_year--; - } - while (tm->tm_mon >= 12) { - tm->tm_mon -= 12; - tm->tm_year++; - } - while (tm->tm_mday <= 0) { - if (tm->tm_mon) { - tm->tm_mon--; - } else { - tm->tm_mon = 11; - tm->tm_year--; - } - tm->tm_mday += nbDaysInMonth(tm->tm_mon, tm->tm_year); - } - - while (tm->tm_mday > nbDaysInMonth(tm->tm_mon, tm->tm_year)) { - tm->tm_mday -= nbDaysInMonth(tm->tm_mon, tm->tm_year); - if (tm->tm_mon < 11) { - tm->tm_mon++; - } else { - tm->tm_mon = 0; - tm->tm_year++; - } - } -} diff --git a/lib-lib/date.h b/lib-lib/date.h deleted file mode 100644 index a1182f4..0000000 --- a/lib-lib/date.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * Copyright © 2006 Pierre Habouzit - */ - -#ifndef MUTT_LIB_LIB_DATE_H -#define MUTT_LIB_LIB_DATE_H - -time_t mutt_local_tz(time_t); -time_t mutt_mktime(struct tm *, int); -void mutt_normalize_time(struct tm *); - -#endif /* MUTT_LIB_LIB_STR_H */ diff --git a/lib-lib/lib-lib.h b/lib-lib/lib-lib.h index edee99b..04d914c 100644 --- a/lib-lib/lib-lib.h +++ b/lib-lib/lib-lib.h @@ -116,7 +116,6 @@ typedef union __attribute__((transparent_union)) anytype { #include "array.h" #include "bits.h" #include "buffer.h" -#include "date.h" #include "file.h" #include "hash.h" #include "list.h" diff --git a/lib-mime/rfc822parse.c b/lib-mime/rfc822parse.c index c39eccc..3afeb7c 100644 --- a/lib-mime/rfc822parse.c +++ b/lib-mime/rfc822parse.c @@ -592,20 +592,22 @@ time_t mutt_parse_date(const char *s, HEADER *h) { struct tm tm; const char *loc; - loc = setlocale(LC_TIME, "C"); + time_t tz; + loc = setlocale(LC_ALL, "C"); p_clear(&tm, 1); if (strptime(s, "%a, %d %b %Y %H:%M:%S %z", &tm)) goto ok; p_clear(&tm, 1); if (strptime(s, "%a, %d %b %Y %H:%M %z", &tm)) goto ok; - setlocale(LC_TIME, loc); + setlocale(LC_ALL, ""); return 0; ok: - setlocale(LC_TIME, loc); - return mutt_mktime(&tm, 1); + setlocale(LC_ALL, ""); + tz = tm.tm_gmtoff; + return timegm(&tm) - tz; } string_list_t **mutt_parse_rfc822_line(ENVELOPE *e, HEADER *hdr, char *line, char *p, @@ -1121,7 +1123,9 @@ bool is_from(const char *s, char *path, ssize_t pathlen, time_t *tp) return false; ok: - if (tp) - *tp = mutt_mktime(&tm, 1); + if (tp) { + *tp = tm.tm_gmtoff; + *tp = timegm(&tm) - *tp; + } return true; } diff --git a/lib-mx/mbox.c b/lib-mx/mbox.c index ae82b66..857ba86 100644 --- a/lib-mx/mbox.c +++ b/lib-mx/mbox.c @@ -99,7 +99,10 @@ static int mbox_parse_mailbox (CONTEXT * ctx) /* precompute the local timezone to speed up calculation of the date received */ - tz = mutt_local_tz (0); + { + time_t t = time(NULL); + tz = localtime(&t)->tm_gmtoff; + } loc = ftello (ctx->fp); while (fgets (buf, sizeof (buf), ctx->fp) != NULL) { diff --git a/pattern.c b/pattern.c index 6e213a2..7744e95 100644 --- a/pattern.c +++ b/pattern.c @@ -384,8 +384,8 @@ static const char *get_offset (struct tm *tm, const char *s, int sign) default: return s; } - mutt_normalize_time (tm); - return (ps + 1); + mktime(tm); + return ps + 1; } static void adjust_date_range (struct tm *min, struct tm *max) @@ -602,8 +602,8 @@ static int eat_date (pattern_t * pat, BUFFER * s, BUFFER * err) /* Since we allow two dates to be specified we'll have to adjust that. */ adjust_date_range (&min, &max); - pat->min = mutt_mktime (&min, 1); - pat->max = mutt_mktime (&max, 1); + pat->min = mktime(&min); + pat->max = mktime(&max); p_delete(&buffer.data); -- 2.20.1