From 9f67a9125363ff07a28312e7c3fa8229db669345 Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Thu, 13 May 2004 09:28:52 +0000 Subject: [PATCH] MacOS-X compatibility tweaks git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19298 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 1 + Source/NSCalendarDate.m | 44 +++++++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8776fda32..945dbff57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ a couple of logs. Also changed to accept nil/empty string values for format and description as MacOS-X does. + Also changed default year to be current year for compatibility. 2004-05-12 Richard Frith-Macdonald diff --git a/Source/NSCalendarDate.m b/Source/NSCalendarDate.m index e0412f595..728c4c24a 100644 --- a/Source/NSCalendarDate.m +++ b/Source/NSCalendarDate.m @@ -576,15 +576,20 @@ static inline int getDigits(const char *from, char *to, int limit) * %Z time zone abbreviation * * + * If no year is specified in the format, the current year is assumed.
+ * If no month is specified in the format, January is assumed.
+ * If no day is specified in the format, 1 is assumed.
+ * If no hour is specified in the format, 0 is assumed.
+ * If no minute is specified in the format, 0 is assumed.
+ * If no second is specified in the format, 0 is assumed.
+ * If no millisecond is specified in the format, 0 is assumed.
+ * If no timezone is specified in the format, the local timezone is assumed. */ - (id) initWithString: (NSString*)description calendarFormat: (NSString*)fmt locale: (NSDictionary*)locale { int milliseconds = 0; - /* Default to gregorian year one ... there is no year zero and - * the algorithms we use look odd for earlier dates. - */ int year = 1; int month = 1; int day = 1; @@ -1167,15 +1172,15 @@ static inline int getDigits(const char *from, char *to, int limit) if (julianWeeks != -1) { - NSTimeZone *gmtZone; + NSTimeZone *gmtZone; NSCalendarDate *d; - int currDay; + int currDay; gmtZone = [NSTimeZone timeZoneForSecondsFromGMT: 0]; if ((had & (hadY|hadw)) != (hadY|hadw)) { - NSCalendarDate *now = [NSCalendarDate date]; + NSCalendarDate *now = [[NSCalendarDate alloc] init]; [now setTimeZone: gmtZone]; if ((had | hadY) == 0) @@ -1188,16 +1193,18 @@ static inline int getDigits(const char *from, char *to, int limit) dayOfWeek = [now dayOfWeek]; had |= hadw; } + RELEASE(now); } - d = [NSCalendarDate dateWithYear: year - month: 1 - day: 1 - hour: 0 - minute: 0 - second: 0 - timeZone: gmtZone]; + d = [[NSCalendarDate alloc] initWithYear: year + month: 1 + day: 1 + hour: 0 + minute: 0 + second: 0 + timeZone: gmtZone]; currDay = [d dayOfWeek]; + RELEASE(d); /* * The julian weeks are either sunday relative or monday relative @@ -1220,6 +1227,17 @@ static inline int getDigits(const char *from, char *to, int limit) had |= hadD; } + /* + * If the year has not been set ... use this year ... as on MacOS-X + */ + if ((had | hadY) == 0) + { + NSCalendarDate *now = [[NSCalendarDate alloc] init]; + + year = [now yearOfCommonEra]; + RELEASE(now); + } + self = [self initWithYear: year month: month day: day