diff --git a/ChangeLog b/ChangeLog index 3ded9f878..8f9536716 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-01 Stefan Bidigaray + + * Headers/Foundation/NSCalendar.h: + * Source/NSLocale.m: Minor fixes. + * Source/NSCalendar.m: Implemented +currentCalendar. + 2011-01-01 Stefan Bidigaray * Source/NSLocale.m: Fixed typos found by testsuite. diff --git a/Headers/Foundation/NSCalendar.h b/Headers/Foundation/NSCalendar.h index 54b0d6969..7232a1d6b 100644 --- a/Headers/Foundation/NSCalendar.h +++ b/Headers/Foundation/NSCalendar.h @@ -30,6 +30,7 @@ #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) #include +#include @class NSDate; @class NSCalendar; diff --git a/Source/NSCalendar.m b/Source/NSCalendar.m index 96afaf423..c9b461788 100644 --- a/Source/NSCalendar.m +++ b/Source/NSCalendar.m @@ -137,13 +137,15 @@ static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit) + (id) currentCalendar { NSCalendar *result = nil; - NSLocale *locale; + NSCalendar *cal; - locale = [NSLocale currentLocale]; +#if GS_USE_ICU == 1 + cal = [[NSLocale currentLocale] objectForKey: NSLocaleCalendar]; + result = + [[NSCalendar alloc] initWithCalendarIdentifier: [cal calendarIdentifier]]; +#endif - // FIXME - - return result; + return AUTORELEASE(result); } - (id) initWithCalendarIdentifier: (NSString *) string @@ -351,8 +353,9 @@ static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit) #if GS_USE_ICU == 1 [self _openCalendar]; return ucal_getAttribute (_cal, UCAL_FIRST_DAY_OF_WEEK); -#endif +#else return 0; +#endif } - (void) setFirstWeekday: (NSUInteger) weekday @@ -360,8 +363,9 @@ static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit) #if GS_USE_ICU == 1 [self _openCalendar]; ucal_setAttribute (_cal, UCAL_FIRST_DAY_OF_WEEK, (int32_t)weekday); -#endif +#else return; +#endif } - (NSUInteger) minimumDaysInFirstWeek @@ -369,8 +373,9 @@ static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit) #if GS_USE_ICU == 1 [self _openCalendar]; return ucal_getAttribute (_cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK); -#endif +#else return 1; +#endif } - (void) setMinimumDaysInFirstWeek: (NSUInteger) mdw @@ -378,8 +383,9 @@ static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit) #if GS_USE_ICU == 1 [self _openCalendar]; ucal_setAttribute (_cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, (int32_t)mdw); -#endif +#else return; +#endif } - (NSTimeZone *) timeZone diff --git a/Source/NSLocale.m b/Source/NSLocale.m index 3c5aa8c4c..cc1109e55 100644 --- a/Source/NSLocale.m +++ b/Source/NSLocale.m @@ -819,7 +819,7 @@ static NSRecursiveLock *classLock = nil; localeId = [NSString stringWithUTF8String: cLocaleId]; #else - localeId = string; + localeId = [NSLocale canonicalLocaleIdentifierFromString: string]; #endif [classLock lock]; @@ -933,7 +933,10 @@ static NSRecursiveLock *classLock = nil; - (id) copyWithZone: (NSZone *) zone { - return RETAIN(self); + if (NSShouldRetainWithZone(self, zone)) + return RETAIN(self); + else + return NSCopyObject(self, 0, zone); } @end