Jim Meyering wrote: > Would you mind separating that into a few separate change sets?
No problem, I splitted the main patch into smaller sub-patches, it is still not complete set of changes, following 3 gnulib getdate.y patches are fixing only issue #2 and #3. > - in a function definition, the function name must begin in col 1 > - new pointer parameters must be const > - adjust type of new, time-related parameters. at least one should be time_t Thanks for spotting time_t for seconds and function name not in col 1. I'm not sure about the const for pointer params, as I have to modify this parser_control *pc (to extract infos from arguments and store them or to pass information about wrong date format spotted). Or you meant something else? Could you please clarify that? TIA. > For coreutils, please add a NEWS entry for each bug fix. I did summary for those three gnulib patches and added one test to the date test. Hope that it's sufficient. Test will pass only if at least getdate.y patches #1 and #3 are applied. > I will have time next week to give this a more thorough review. Thanks in advance, I hope I will do the rest of patches ( 1 or 2 more are still necessary to cover all the issues I found). Greetings, Ondrej
From 4c9db16207b5c76bb85b05ee5853c525372bb80a Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= <[EMAIL PROTECTED]> Date: Fri, 27 Jun 2008 16:32:28 +0200 Subject: [PATCH] *lib/getdate.y: Do not ignore specified time zone when relative offset for days/months/years is specified. Signed-off-by: Ondřej Vašík <[EMAIL PROTECTED]> --- lib/getdate.y | 40 ++++++++++++++++++++-------------------- 1 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/getdate.y b/lib/getdate.y index 1deec51..7b55c31 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -1436,26 +1436,7 @@ get_date (struct timespec *result, char const *p, struct timespec const *now) goto fail; } - if (pc.zones_seen) - { - long int delta = pc.time_zone * 60; - time_t t1; -#ifdef HAVE_TM_GMTOFF - delta -= tm.tm_gmtoff; -#else - time_t t = Start; - struct tm const *gmt = gmtime (&t); - if (! gmt) - goto fail; - delta -= tm_diff (&tm, gmt); -#endif - t1 = Start - delta; - if ((Start < t1) != (delta < 0)) - goto fail; /* time_t overflow */ - Start = t1; - } - - /* Add relative date. */ + /* Add relative date. */ if (pc.rel.year | pc.rel.month | pc.rel.day) { int year = tm.tm_year + pc.rel.year; @@ -1477,6 +1458,25 @@ get_date (struct timespec *result, char const *p, struct timespec const *now) goto fail; } + if (pc.zones_seen) + { + long int delta = pc.time_zone * 60; + time_t t1; +#ifdef HAVE_TM_GMTOFF + delta -= tm.tm_gmtoff; +#else + time_t t = Start; + struct tm const *gmt = gmtime (&t); + if (! gmt) + goto fail; + delta -= tm_diff (&tm, gmt); +#endif + t1 = Start - delta; + if ((Start < t1) != (delta < 0)) + goto fail; /* time_t overflow */ + Start = t1; + } + /* Add relative hours, minutes, and seconds. On hosts that support leap seconds, ignore the possibility of leap seconds; e.g., "+ 10 minutes" adds 600 seconds, even if one of them is a -- 1.5.2.2
From 9eb2711cd03b3825e36cff33e7e7fccbbfc504d1 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= <[EMAIL PROTECTED]> Date: Fri, 27 Jun 2008 17:37:40 +0200 Subject: [PATCH] *lib/getdate.y: Factorize duplicate code for relative time offset and hhmmss times. Signed-off-by: Ondřej Vašík <[EMAIL PROTECTED]> --- lib/getdate.y | 86 ++++++++++++++++++++++----------------------------------- 1 files changed, 33 insertions(+), 53 deletions(-) diff --git a/lib/getdate.y b/lib/getdate.y index 7b55c31..e4f2598 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -246,6 +246,30 @@ digits_to_date_time (parser_control *pc, textint text_int) } } +/* Extract relative time multiplied by factor into *pc */ +static void +extract_relative_time (parser_control *pc, relative_time rel, int factor) +{ + pc->rel.ns += factor*rel.ns; + pc->rel.seconds += factor*rel.seconds; + pc->rel.minutes += factor*rel.minutes; + pc->rel.hour += factor*rel.hour; + pc->rel.day += factor*rel.day; + pc->rel.month += factor*rel.month; + pc->rel.year += factor*rel.year; + pc->rels_seen = true; +} + +/* Extract hours, minutes, seconds and nanoseconds from arguments into *pc */ +static void +extract_hhmmss (parser_control *pc, long int ho, long int mi, time_t sec, long int nsec) +{ + pc->hour = ho; + pc->minutes = mi; + pc->seconds.tv_sec = sec; + pc->seconds.tv_nsec = nsec; +} + %} /* We want a reentrant parser, even if the TZ manipulation and the calls to @@ -313,7 +337,6 @@ item: | day { pc->days_seen++; } | rel - { pc->rels_seen = true; } | number | hybrid ; @@ -321,42 +344,29 @@ item: time: tUNUMBER tMERIDIAN { - pc->hour = $1.value; - pc->minutes = 0; - pc->seconds.tv_sec = 0; - pc->seconds.tv_nsec = 0; + extract_hhmmss (pc, $1.value, 0, 0, 0); pc->meridian = $2; } | tUNUMBER ':' tUNUMBER o_merid { - pc->hour = $1.value; - pc->minutes = $3.value; - pc->seconds.tv_sec = 0; - pc->seconds.tv_nsec = 0; + extract_hhmmss (pc, $1.value, $3.value, 0, 0); pc->meridian = $4; } | tUNUMBER ':' tUNUMBER tSNUMBER o_colon_minutes { - pc->hour = $1.value; - pc->minutes = $3.value; - pc->seconds.tv_sec = 0; - pc->seconds.tv_nsec = 0; + extract_hhmmss (pc, $1.value, $3.value, 0, 0); pc->meridian = MER24; pc->zones_seen++; pc->time_zone = time_zone_hhmm ($4, $5); } | tUNUMBER ':' tUNUMBER ':' unsigned_seconds o_merid { - pc->hour = $1.value; - pc->minutes = $3.value; - pc->seconds = $5; + extract_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec); pc->meridian = $6; } | tUNUMBER ':' tUNUMBER ':' unsigned_seconds tSNUMBER o_colon_minutes { - pc->hour = $1.value; - pc->minutes = $3.value; - pc->seconds = $5; + extract_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec); pc->meridian = MER24; pc->zones_seen++; pc->time_zone = time_zone_hhmm ($6, $7); @@ -381,14 +391,7 @@ zone: { pc->time_zone = $1; } | tZONE relunit_snumber { pc->time_zone = $1; - pc->rel.ns += $2.ns; - pc->rel.seconds += $2.seconds; - pc->rel.minutes += $2.minutes; - pc->rel.hour += $2.hour; - pc->rel.day += $2.day; - pc->rel.month += $2.month; - pc->rel.year += $2.year; - pc->rels_seen = true; } + extract_relative_time (pc, $2, 1); } | tZONE tSNUMBER o_colon_minutes { pc->time_zone = $1 + time_zone_hhmm ($2, $3); } | tDAYZONE @@ -495,25 +498,9 @@ date: rel: relunit tAGO - { - pc->rel.ns -= $1.ns; - pc->rel.seconds -= $1.seconds; - pc->rel.minutes -= $1.minutes; - pc->rel.hour -= $1.hour; - pc->rel.day -= $1.day; - pc->rel.month -= $1.month; - pc->rel.year -= $1.year; - } + { extract_relative_time (pc, $1, -1); } | relunit - { - pc->rel.ns += $1.ns; - pc->rel.seconds += $1.seconds; - pc->rel.minutes += $1.minutes; - pc->rel.hour += $1.hour; - pc->rel.day += $1.day; - pc->rel.month += $1.month; - pc->rel.year += $1.year; - } + { extract_relative_time (pc, $1, 1); } ; relunit: @@ -600,14 +587,7 @@ hybrid: /* Hybrid all-digit and relative offset, so that we accept e.g., "YYYYMMDD +N days" as well as "YYYYMMDD N days". */ digits_to_date_time (pc, $1); - pc->rel.ns += $2.ns; - pc->rel.seconds += $2.seconds; - pc->rel.minutes += $2.minutes; - pc->rel.hour += $2.hour; - pc->rel.day += $2.day; - pc->rel.month += $2.month; - pc->rel.year += $2.year; - pc->rels_seen = true; + extract_relative_time (pc, $2, 1); } ; -- 1.5.2.2
From f849e4312073f8820784ed0c3621727f703e6cf5 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= <[EMAIL PROTECTED]> Date: Fri, 27 Jun 2008 18:05:26 +0200 Subject: [PATCH] *lib/getdate.y: No longer allow invalid timezones(UTC-12 to UTC+14 allowed), consider TZ string -14 to +14 as hours(and add minutes if no minutes are specified) Signed-off-by: Ondřej Vašík <[EMAIL PROTECTED]> --- lib/getdate.y | 31 +++++++++++++++++++++++-------- 1 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/getdate.y b/lib/getdate.y index e4f2598..f33c0a4 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -205,7 +205,7 @@ typedef struct union YYSTYPE; static int yylex (union YYSTYPE *, parser_control *); static int yyerror (parser_control const *, char const *); -static long int time_zone_hhmm (textint, long int); +static long int time_zone_hhmm (parser_control *, textint, long int); /* Extract into *PC any date and time info from a string of digits of the form e.g., YYYYMMDD, YYMMDD, HHMM, HH (and sometimes YYY, @@ -357,7 +357,7 @@ time: extract_hhmmss (pc, $1.value, $3.value, 0, 0); pc->meridian = MER24; pc->zones_seen++; - pc->time_zone = time_zone_hhmm ($4, $5); + pc->time_zone = time_zone_hhmm (pc, $4, $5); } | tUNUMBER ':' tUNUMBER ':' unsigned_seconds o_merid { @@ -369,7 +369,7 @@ time: extract_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec); pc->meridian = MER24; pc->zones_seen++; - pc->time_zone = time_zone_hhmm ($6, $7); + pc->time_zone = time_zone_hhmm (pc, $6, $7); } ; @@ -393,7 +393,7 @@ zone: { pc->time_zone = $1; extract_relative_time (pc, $2, 1); } | tZONE tSNUMBER o_colon_minutes - { pc->time_zone = $1 + time_zone_hhmm ($2, $3); } + { pc->time_zone = $1 + time_zone_hhmm (pc, $2, $3); } | tDAYZONE { pc->time_zone = $1 + 60; } | tZONE tDST @@ -794,15 +794,30 @@ static table const military_table[] = /* Convert a time zone expressed as HH:MM into an integer count of minutes. If MM is negative, then S is of the form HHMM and needs - to be picked apart; otherwise, S is of the form HH. */ + to be picked apart; otherwise, S is of the form HH. Check for + possibly invalid time zones formats */ static long int -time_zone_hhmm (textint s, long int mm) +time_zone_hhmm (parser_control *pc, textint s, long int mm) { + long int returnvalue; + /* if s.value is lower than 15, add 00 minutes if mm not specified + as common time zones ranges between UTC-1200 and UTC+1400 */ + if ((abs(s.value) < 15) && (mm < 0)) + s.value *= 100; + if (mm < 0) - return (s.value / 100) * 60 + s.value % 100; + returnvalue = (s.value / 100) * 60 + s.value % 100; else - return s.value * 60 + (s.negative ? -mm : mm); + returnvalue = s.value * 60 + (s.negative ? -mm : mm); + + /* check if the return value is in real timezone range, + otherwise increment pc->zones_seen to cause time format + error, allow UTC-1200 to UTC+1400 */ + if ((returnvalue > 840) || (returnvalue < -720)) + pc->zones_seen++; + + return returnvalue; } static int -- 1.5.2.2
From 7955f38d84830409e93e200048559bbc5ce4a7ae Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= <[EMAIL PROTECTED]> Date: Fri, 27 Jun 2008 17:59:15 +0200 Subject: [PATCH] tests/misc/date: test if TZ is not ignored for relative day offset NEWS: mention changes in date behaviour Signed-off-by: Ondřej Vašík <[EMAIL PROTECTED]> --- NEWS | 6 ++++++ tests/misc/date | 2 ++ 2 files changed, 8 insertions(+), 0 deletions(-) diff --git a/NEWS b/NEWS index c38088d..b8e6f07 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,9 @@ GNU coreutils NEWS -*- outline -*- chcon --verbose now prints a newline after each message + date will no longer ignore specified timezone when relative day,month + or year offset is specified. + od no longer suffers from platform bugs in printf(3). This is probably most noticeable when using 'od -tfL' to print long doubles. @@ -51,6 +54,9 @@ GNU coreutils NEWS -*- outline -*- stat's --context (-Z) option has always been a no-op. Now it evokes a warning that it is obsolete and will be removed. + date will now consider invalid timezone in format as invalid + date(UTC-12 to UTC+14 allowed) + * Noteworthy changes in release 6.12 (2008-05-31) [stable] diff --git a/tests/misc/date b/tests/misc/date index fb700b5..96c7fa6 100755 --- a/tests/misc/date +++ b/tests/misc/date @@ -118,6 +118,8 @@ my @Tests = ['rel-1day', "-d '20050101 1 day' +%F", {OUT=>"2005-01-02"}], # ...but up to coreutils-6.9, this was rejected due to the "+". ['rel-plus1', "-d '20050101 +1 day' +%F", {OUT=>"2005-01-02"}], + # up to 6.12, specified TZ was ignored with relative day offset + ['rel-plusTZ6d', "-d '20070101 12:40 UTC+4 +6 day' $fmt", {OUT=>"2007-01-07 08:40:00"}], ['next-s', "-d '$d1 next second' '+%Y-%m-%d %T'", {OUT=>"$d0 $ts"}], ['next-m', "-d '$d1 next minute' '+%Y-%m-%d %T'", {OUT=>"$d0 $tm"}], -- 1.5.2.2
signature.asc
Description: Toto je digitálně podepsaná část zprávy
_______________________________________________ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils