mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-30 03:50:46 +00:00
Fixed initialization bug in NSDateFormatter and implement NSCalendar-components:fromDate:
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31933 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
07f39f7639
commit
e40d187b01
3 changed files with 43 additions and 2 deletions
|
@ -3,6 +3,11 @@
|
|||
* libs/base/trunk/Source/NSNumberFormatter.m: Some small fixes in
|
||||
NSNumberFormatter. Mostly stop using == to compare C strings.
|
||||
|
||||
2011-01-22 Stefan Bidigaray <stefanbidi@gmail.com>
|
||||
|
||||
* Source/NSDateFormatter.m: Initialize UDateFormat before using it.
|
||||
* Source/NSCalendar.m: Implement -components:fromDate:.
|
||||
|
||||
2011-01-22 Stefan Bidigaray <stefanbidi@gmail.com>
|
||||
|
||||
* Source/NSDateFormatter.m: Implemented a few more methods.
|
||||
|
|
|
@ -203,6 +203,7 @@ static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit)
|
|||
_localeId = RETAIN([self _localeIdWithLocale: [NSLocale currentLocale]]);
|
||||
_tz = RETAIN([NSTimeZone defaultTimeZone]);
|
||||
|
||||
[self _openCalendar];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -225,7 +226,42 @@ static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit)
|
|||
- (NSDateComponents *) components: (NSUInteger) unitFlags
|
||||
fromDate: (NSDate *) date
|
||||
{
|
||||
#if GS_USE_ICU == 1
|
||||
NSDateComponents *comps;
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
UDate udate;
|
||||
|
||||
udate = (UDate)floor([date timeIntervalSince1970] * 1000.0);
|
||||
ucal_setMillis (_cal, udate, &err);
|
||||
if (U_FAILURE(err))
|
||||
return nil;
|
||||
|
||||
comps = [[NSDateComponents alloc] init];
|
||||
if (unitFlags & NSEraCalendarUnit)
|
||||
[comps setEra: ucal_get (_cal, UCAL_ERA, &err)];
|
||||
if (unitFlags & NSYearCalendarUnit)
|
||||
[comps setYear: ucal_get (_cal, UCAL_YEAR, &err)];
|
||||
if (unitFlags & NSMonthCalendarUnit)
|
||||
[comps setMonth: ucal_get (_cal, UCAL_MONTH, &err)];
|
||||
if (unitFlags & NSDayCalendarUnit)
|
||||
[comps setDay: ucal_get (_cal, UCAL_DAY_OF_MONTH, &err)];
|
||||
if (unitFlags & NSHourCalendarUnit)
|
||||
[comps setHour: ucal_get (_cal, UCAL_HOUR_OF_DAY, &err)];
|
||||
if (unitFlags & NSMinuteCalendarUnit)
|
||||
[comps setMinute: ucal_get (_cal, UCAL_MINUTE, &err)];
|
||||
if (unitFlags & NSSecondCalendarUnit)
|
||||
[comps setSecond: ucal_get (_cal, UCAL_SECOND, &err)];
|
||||
if (unitFlags & NSWeekCalendarUnit)
|
||||
[comps setWeek: ucal_get (_cal, UCAL_WEEK_OF_YEAR, &err)];
|
||||
if (unitFlags & NSWeekdayCalendarUnit)
|
||||
[comps setWeekday: ucal_get (_cal, UCAL_DAY_OF_WEEK, &err)];
|
||||
if (unitFlags & NSWeekdayOrdinalCalendarUnit)
|
||||
[comps setWeekdayOrdinal: ucal_get (_cal, UCAL_WEEK_OF_MONTH, &err)];
|
||||
|
||||
return AUTORELEASE(comps);
|
||||
#else
|
||||
return nil;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (NSDateComponents *) components: (NSUInteger) unitFlags
|
||||
|
|
|
@ -88,6 +88,8 @@ static NSDateFormatterBehavior _defaultBehavior = 0;
|
|||
_locale = RETAIN([NSLocale currentLocale]);
|
||||
_tz = RETAIN([NSTimeZone defaultTimeZone]);
|
||||
|
||||
[self _resetUDateFormat];
|
||||
|
||||
/* According to Apple docs, default behavior is NSDateFormatterBehavior10_4 on
|
||||
10.5 and later. Yeah, go figure. */
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST) && GS_USE_ICU == 1
|
||||
|
@ -107,8 +109,6 @@ static NSDateFormatterBehavior _defaultBehavior = 0;
|
|||
NSZoneFree ([self zone], value);
|
||||
#endif
|
||||
|
||||
[self _resetUDateFormat];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue