From ede9936f504281c9d41f25868dca540f8dae704e Mon Sep 17 00:00:00 2001 From: Fumitoshi UKAI Date: Fri, 27 Dec 2002 15:53:03 +0000 Subject: [w3m-dev 03607] mymktime: time zone support * etc.c (get_zone): added (mymktime): parse timezone From: Hironori SAKAMOTO --- ChangeLog | 8 +++++++- etc.c | 44 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index f8530ac..6434626 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-12-28 Hironori SAKAMOTO + + * [w3m-dev 03607] mymktime: time zone support + * etc.c (get_zone): added + (mymktime): parse timezone + 2002-12-28 Hironori SAKAMOTO * [w3m-dev 03606] Re: clean up displayBuffer() @@ -6097,4 +6103,4 @@ a * [w3m-dev 03276] compile error on EWS4800 * release-0-2-1 * import w3m-0.2.1 -$Id: ChangeLog,v 1.650 2002/12/27 15:50:32 ukai Exp $ +$Id: ChangeLog,v 1.651 2002/12/27 15:53:03 ukai Exp $ diff --git a/etc.c b/etc.c index 157f38f..717c1ba 100644 --- a/etc.c +++ b/etc.c @@ -1,4 +1,4 @@ -/* $Id: etc.c,v 1.44 2002/12/24 17:20:46 ukai Exp $ */ +/* $Id: etc.c,v 1.45 2002/12/27 15:53:04 ukai Exp $ */ #include "fm.h" #include #include "myctype.h" @@ -1646,12 +1646,38 @@ get_time(char **s, int *hour, int *min, int *sec) return 0; } +static int +get_zone(char **s, int *z_hour, int *z_min) +{ + Str tmp = Strnew(); + int zone; + char *ss = *s; + + if (!**s) + return -1; + + if (**s == '+' || **s == '-') + Strcat_char(tmp, *((*s)++)); + while (**s && IS_DIGIT(**s)) + Strcat_char(tmp, *((*s)++)); + if (!(tmp->length == 4 && IS_DIGIT(*ss)) && + !(tmp->length == 5 && (*ss == '+' || *ss == '-'))) { + *s = ss; + return -1; + } + + zone = atoi(tmp->ptr); + *z_hour = zone / 100; + *z_min = zone - (zone / 100) * 100; + return 0; +} + /* RFC 1123 or RFC 850 or ANSI C asctime() format string -> time_t */ time_t mymktime(char *timestr) { char *s; - int day, mon, year, hour, min, sec; + int day, mon, year, hour, min, sec, z_hour = 0, z_min = 0; if (!(timestr && *timestr)) return -1; @@ -1688,8 +1714,12 @@ mymktime(char *timestr) min = 0; sec = 0; } - else if (get_time(&s, &hour, &min, &sec) == -1) { - return -1; + else { + if (get_time(&s, &hour, &min, &sec) == -1) + return -1; + while (*s && !IS_DIGIT(*s) && *s != '+' && *s != '-') + s++; + get_zone(&s, &z_hour, &z_min); } } else { @@ -1715,8 +1745,8 @@ mymktime(char *timestr) return -1; } #ifdef DEBUG - fprintf(stderr, "year=%d month=%d day=%d hour:min:sec=%d:%d:%d\n", - year, mon, day, hour, min, sec); + fprintf(stderr, "year=%d month=%d day=%d hour:min:sec=%d:%d:%d zone=%d:%d\n", + year, mon, day, hour, min, sec, z_hour, z_min); #endif /* DEBUG */ mon -= 3; @@ -1726,6 +1756,8 @@ mymktime(char *timestr) } day += (year - 1968) * 1461 / 4; day += ((((mon * 153) + 2) / 5) - 672); + hour -= z_hour; + min -= z_min; return (time_t) ((day * 60 * 60 * 24) + (hour * 60 * 60) + (min * 60) + sec); } -- cgit v1.2.3