From 2e27ec369165aca385db16cb617ced30928ced42 Mon Sep 17 00:00:00 2001 From: hobbs Date: Thu, 18 Oct 2001 20:20:28 +0000 Subject: * tests/clock.test (clock-8.1): * generic/tclDate.c (RelativeMonth): * generic/tclGetDate.y (RelativeMonth): corrected off-by-one-day error in clock scan with relative months and years during swing hours. [Bug #413397, Patch #414024] (lavana) --- ChangeLog | 8 ++++++++ generic/tclDate.c | 19 ++++++++++++++++++- generic/tclGetDate.y | 19 ++++++++++++++++++- tests/clock.test | 13 +++++++++++-- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 400db3e..dfca7f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-10-18 Jeff Hobbs + + * tests/clock.test (clock-8.1): + * generic/tclDate.c (RelativeMonth): + * generic/tclGetDate.y (RelativeMonth): corrected off-by-one-day + error in clock scan with relative months and years during swing + hours. [Bug #413397, Patch #414024] (lavana) + 2001-10-18 Vince Darley * generic/tclIOUtil.c: fix to bug in Tcl_FSChdir shown up diff --git a/generic/tclDate.c b/generic/tclDate.c index 29f9037..31576d2 100644 --- a/generic/tclDate.c +++ b/generic/tclDate.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclDate.c,v 1.19 2001/07/31 19:12:06 vincentdarley Exp $ + * RCS: @(#) $Id: tclDate.c,v 1.20 2001/10/18 20:20:28 hobbs Exp $ */ #include "tclInt.h" @@ -579,6 +579,23 @@ RelativeMonth(Start, RelMonth, TimePtr) result = Convert(Month, (time_t) tm->tm_mday, Year, (time_t) tm->tm_hour, (time_t) tm->tm_min, (time_t) tm->tm_sec, MER24, DSTmaybe, &Julian); + + /* + * The Julian time returned above is behind by one day, if "month" + * or "year" is used to specify relative time and the GMT flag is true. + * This problem occurs only when the current time is closer to + * midnight, the difference being not more than its time difference + * with GMT. For example, in US/Pacific time zone, the problem occurs + * whenever the current time is between midnight to 8:00am or 7:00amDST. + * See Bug# 413397 for more details and sample script. + * To resolve this bug, we simply add the number of seconds corresponding + * to timezone difference with GMT to Julian time, if GMT flag is true. + */ + + if (TclDateTimezone == 0) { + Julian += TclpGetTimeZone((unsigned long) Start) * 60L; + } + /* * The following iteration takes into account the case were we jump * into a "short month". Far example, "one month from Jan 31" will diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y index dd3310b..14b9869 100644 --- a/generic/tclGetDate.y +++ b/generic/tclGetDate.y @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclGetDate.y,v 1.17 2001/07/31 19:12:06 vincentdarley Exp $ + * RCS: @(#) $Id: tclGetDate.y,v 1.18 2001/10/18 20:20:28 hobbs Exp $ */ %{ @@ -798,6 +798,23 @@ RelativeMonth(Start, RelMonth, TimePtr) result = Convert(Month, (time_t) tm->tm_mday, Year, (time_t) tm->tm_hour, (time_t) tm->tm_min, (time_t) tm->tm_sec, MER24, DSTmaybe, &Julian); + + /* + * The Julian time returned above is behind by one day, if "month" + * or "year" is used to specify relative time and the GMT flag is true. + * This problem occurs only when the current time is closer to + * midnight, the difference being not more than its time difference + * with GMT. For example, in US/Pacific time zone, the problem occurs + * whenever the current time is between midnight to 8:00am or 7:00amDST. + * See Bug# 413397 for more details and sample script. + * To resolve this bug, we simply add the number of seconds corresponding + * to timezone difference with GMT to Julian time, if GMT flag is true. + */ + + if (TclDateTimezone == 0) { + Julian += TclpGetTimeZone((unsigned long) Start) * 60L; + } + /* * The following iteration takes into account the case were we jump * into a "short month". Far example, "one month from Jan 31" will diff --git a/tests/clock.test b/tests/clock.test index 776586b..c96c2e7 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -10,7 +10,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: clock.test,v 1.16 2001/07/03 20:48:38 mdejong Exp $ +# RCS: @(#) $Id: clock.test,v 1.17 2001/10/18 20:20:28 hobbs Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -418,7 +418,16 @@ test clock-7.3 {clock scan next monthname} { -format %m.%Y } "05.2001" +# We use 5am PST, 31-12-1999 as the base for these scans because irrespective +# of your local timezone it should always give us times on December 31 +set 5amPST 946645200 +test clock-8.1 {clock scan midnight/gmt range bug 413397} { + set fmt "%m/%d" + list [clock format [clock scan year -base $5amPST -gmt 0] -format $fmt] \ + [clock format [clock scan year -base $5amPST -gmt 1] -format $fmt] +} {12/31 12/31} + + # cleanup ::tcltest::cleanupTests return - -- cgit v0.12