From 4fa4c00318efddb1a68a99cb4b078eef0eadbd20 Mon Sep 17 00:00:00 2001 From: rfm Date: Mon, 23 Oct 2006 12:24:52 +0000 Subject: [PATCH] Fix bug #18088 git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23950 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Headers/Foundation/NSCalendarDate.h | 2 +- Source/NSCalendarDate.m | 16 ++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index a32ad101b..4709b7b2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-10-23 Richard Frith-Macdonald + + * Source/NSCalendarDate: when adding offset to a date, work in + the timezone for the date rather than in GMT ... fixes bug #18088 + 2006-10-20 Richard Frith-Macdonald * Source/Additions/GSPrivate.m: diff --git a/Headers/Foundation/NSCalendarDate.h b/Headers/Foundation/NSCalendarDate.h index 0cee1c525..3632f85fb 100644 --- a/Headers/Foundation/NSCalendarDate.h +++ b/Headers/Foundation/NSCalendarDate.h @@ -68,7 +68,7 @@ extern "C" { second: (unsigned int)second timeZone: (NSTimeZone*)aTimeZone; -// Retreiving Date Elements +// Retrieving Date Elements - (int) dayOfCommonEra; - (int) dayOfMonth; - (int) dayOfWeek; diff --git a/Source/NSCalendarDate.m b/Source/NSCalendarDate.m index 1f6c1aee9..104df24e6 100644 --- a/Source/NSCalendarDate.m +++ b/Source/NSCalendarDate.m @@ -2378,13 +2378,15 @@ static void Grow(DescriptionInfo *info, unsigned size) NSTimeInterval newOffset; int i, year, month, day, hour, minute, second, mil; - oldOffset = offset(_time_zone, self); - /* - * Break into components in GMT time zone. + /* Apply timezone offset to _seconds_since_ref from GMT to local time, + * then break into components in local time zone. */ - GSBreakTime(_seconds_since_ref, &year, &month, &day, &hour, &minute, - &second, &mil); + oldOffset = offset(_time_zone, self); + s = _seconds_since_ref + oldOffset; + GSBreakTime(s, &year, &month, &day, &hour, &minute, &second, &mil); + /* Apply required offsets to get new local time. + */ while (years != 0 || months != 0 || days != 0 || hours != 0 || minutes != 0 || seconds != 0) { @@ -2473,9 +2475,11 @@ static void Grow(DescriptionInfo *info, unsigned size) } /* - * Reassemble in GMT time zone. + * Reassemble and apply original timezone offset to get + * _seconds_since_ref back to GMT. */ s = GSTime(day, month, year, hour, minute, second, mil); + s -= oldOffset; c = [NSCalendarDate alloc]; c->_calendar_format = cformat; c->_time_zone = RETAIN([self timeZone]);