mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 08:41:03 +00:00
Added code for -maximumRangeOfUnit: and -minimumRangeofUnit:.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31744 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
47fdf3d48d
commit
365393d065
2 changed files with 96 additions and 10 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2010-12-16 Stefan Bidigaray <stefanbidi@gmail.com>
|
||||||
|
|
||||||
|
* Source/NSCalendar.m: Added code for -maximumRangeOfUnit: and
|
||||||
|
-minimumRangeofUnit:.
|
||||||
|
|
||||||
2010-12-16 Richard Frith-Macdonald <rfm@gnu.org>
|
2010-12-16 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSRegularExpression.m: Move towards coding standards compliance
|
* Source/NSRegularExpression.m: Move towards coding standards compliance
|
||||||
|
|
|
@ -34,16 +34,49 @@
|
||||||
#include <unicode/ucal.h>
|
#include <unicode/ucal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if GS_USE_ICU == 1
|
||||||
|
static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit)
|
||||||
|
{
|
||||||
|
// I'm just going to go in the order they appear in Apple's documentation
|
||||||
|
if (unit & NSEraCalendarUnit)
|
||||||
|
return UCAL_ERA;
|
||||||
|
if (unit & NSYearCalendarUnit)
|
||||||
|
return UCAL_YEAR;
|
||||||
|
if (unit & NSMonthCalendarUnit)
|
||||||
|
return UCAL_MONTH;
|
||||||
|
if (unit & NSDayCalendarUnit)
|
||||||
|
return UCAL_DAY_OF_YEAR;
|
||||||
|
if (unit & NSHourCalendarUnit)
|
||||||
|
return UCAL_HOUR_OF_DAY;
|
||||||
|
if (unit & NSMinuteCalendarUnit)
|
||||||
|
return UCAL_MINUTE;
|
||||||
|
if (unit & NSSecondCalendarUnit)
|
||||||
|
return UCAL_SECOND;
|
||||||
|
if (unit & NSWeekCalendarUnit)
|
||||||
|
return UCAL_WEEK_OF_YEAR;
|
||||||
|
if (unit & NSWeekdayCalendarUnit)
|
||||||
|
return UCAL_DAY_OF_WEEK;
|
||||||
|
if (unit & NSWeekdayOrdinalCalendarUnit)
|
||||||
|
// FIXME: Is this right???
|
||||||
|
return UCAL_DAY_OF_WEEK_IN_MONTH;
|
||||||
|
// ICU doesn't include a quarter DateField...
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif /* GS_USE_ICU */
|
||||||
|
|
||||||
@interface NSCalendar (PrivateMethods)
|
@interface NSCalendar (PrivateMethods)
|
||||||
- (void) _openUCalendar;
|
- (void) _openCalendar;
|
||||||
- (void) _closeUCalendar;
|
- (void) _closeCalendar;
|
||||||
- (NSString *) _localeIdWithLocale: (NSLocale *) locale;
|
- (NSString *) _localeIdWithLocale: (NSLocale *) locale;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#define TZ_NAME_LENGTH 1024
|
#define TZ_NAME_LENGTH 1024
|
||||||
|
|
||||||
@implementation NSCalendar (PrivateMethods)
|
@implementation NSCalendar (PrivateMethods)
|
||||||
- (void) _openUCalendar
|
- (void) _openCalendar
|
||||||
{
|
{
|
||||||
#if GS_USE_ICU == 1
|
#if GS_USE_ICU == 1
|
||||||
if (_cal == NULL)
|
if (_cal == NULL)
|
||||||
|
@ -67,7 +100,7 @@
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) _closeUCalendar
|
- (void) _closeCalendar
|
||||||
{
|
{
|
||||||
#if GS_USE_ICU == 1
|
#if GS_USE_ICU == 1
|
||||||
ucal_close (_cal);
|
ucal_close (_cal);
|
||||||
|
@ -101,7 +134,7 @@
|
||||||
|
|
||||||
locale = [NSLocale currentLocale];
|
locale = [NSLocale currentLocale];
|
||||||
|
|
||||||
|
// FIXME
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -148,7 +181,7 @@
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[self _closeUCalendar];
|
[self _closeCalendar];
|
||||||
RELEASE(_identifier);
|
RELEASE(_identifier);
|
||||||
RELEASE(_localeId);
|
RELEASE(_localeId);
|
||||||
RELEASE(_tz);
|
RELEASE(_tz);
|
||||||
|
@ -195,6 +228,10 @@
|
||||||
|
|
||||||
- (void)setLocale: (NSLocale *) locale
|
- (void)setLocale: (NSLocale *) locale
|
||||||
{
|
{
|
||||||
|
if ([[locale localeIdentifier] isEqual: _localeId])
|
||||||
|
return;
|
||||||
|
|
||||||
|
[self _closeCalendar];
|
||||||
RELEASE(_localeId);
|
RELEASE(_localeId);
|
||||||
_localeId = RETAIN([self _localeIdWithLocale: locale]);
|
_localeId = RETAIN([self _localeIdWithLocale: locale]);
|
||||||
}
|
}
|
||||||
|
@ -202,7 +239,7 @@
|
||||||
- (NSUInteger) firstWeekday
|
- (NSUInteger) firstWeekday
|
||||||
{
|
{
|
||||||
#if GS_USE_ICU == 1
|
#if GS_USE_ICU == 1
|
||||||
[self _openUCalendar];
|
[self _openCalendar];
|
||||||
return ucal_getAttribute (_cal, UCAL_FIRST_DAY_OF_WEEK);
|
return ucal_getAttribute (_cal, UCAL_FIRST_DAY_OF_WEEK);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -211,7 +248,7 @@
|
||||||
- (void) setFirstWeekday: (NSUInteger) weekday
|
- (void) setFirstWeekday: (NSUInteger) weekday
|
||||||
{
|
{
|
||||||
#if GS_USE_ICU == 1
|
#if GS_USE_ICU == 1
|
||||||
[self _openUCalendar];
|
[self _openCalendar];
|
||||||
ucal_setAttribute (_cal, UCAL_FIRST_DAY_OF_WEEK, (int32_t)weekday);
|
ucal_setAttribute (_cal, UCAL_FIRST_DAY_OF_WEEK, (int32_t)weekday);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
|
@ -220,7 +257,7 @@
|
||||||
- (NSUInteger) minimumDaysInFirstWeek
|
- (NSUInteger) minimumDaysInFirstWeek
|
||||||
{
|
{
|
||||||
#if GS_USE_ICU == 1
|
#if GS_USE_ICU == 1
|
||||||
[self _openUCalendar];
|
[self _openCalendar];
|
||||||
return ucal_getAttribute (_cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK);
|
return ucal_getAttribute (_cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK);
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -229,7 +266,7 @@
|
||||||
- (void) setMinimumDaysInFirstWeek: (NSUInteger) mdw
|
- (void) setMinimumDaysInFirstWeek: (NSUInteger) mdw
|
||||||
{
|
{
|
||||||
#if GS_USE_ICU == 1
|
#if GS_USE_ICU == 1
|
||||||
[self _openUCalendar];
|
[self _openCalendar];
|
||||||
ucal_setAttribute (_cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, (int32_t)mdw);
|
ucal_setAttribute (_cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, (int32_t)mdw);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
|
@ -242,6 +279,10 @@
|
||||||
|
|
||||||
- (void) setTimeZone: (NSTimeZone *) tz
|
- (void) setTimeZone: (NSTimeZone *) tz
|
||||||
{
|
{
|
||||||
|
if ([tz isEqual: _tz])
|
||||||
|
return;
|
||||||
|
|
||||||
|
[self _closeCalendar];
|
||||||
RELEASE(_tz);
|
RELEASE(_tz);
|
||||||
_tz = RETAIN(tz);
|
_tz = RETAIN(tz);
|
||||||
}
|
}
|
||||||
|
@ -249,12 +290,52 @@
|
||||||
|
|
||||||
- (NSRange) maximumRangeOfUnit: (NSCalendarUnit) unit
|
- (NSRange) maximumRangeOfUnit: (NSCalendarUnit) unit
|
||||||
{
|
{
|
||||||
|
#if GS_USE_ICU == 1
|
||||||
|
UCalendarDateFields dateField;
|
||||||
|
NSRange result;
|
||||||
|
UErrorCode err = U_ZERO_ERROR;
|
||||||
|
|
||||||
|
[self _openCalendar];
|
||||||
|
dateField = _NSCalendarUnitToDateField (unit);
|
||||||
|
// We really don't care if there are any errors...
|
||||||
|
result.location =
|
||||||
|
(NSUInteger)ucal_getLimit (_cal, dateField, UCAL_MINIMUM, &err);
|
||||||
|
result.length =
|
||||||
|
(NSUInteger)ucal_getLimit (_cal, dateField, UCAL_MAXIMUM, &err)
|
||||||
|
- result.location + 1;
|
||||||
|
// ICU's month is 0-based, while NSCalendar is 1-based
|
||||||
|
if (dateField == UCAL_MONTH)
|
||||||
|
result.location += 1;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
#else
|
||||||
return NSMakeRange (0, 0);
|
return NSMakeRange (0, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRange) minimumRangeofUnit: (NSCalendarUnit) unit
|
- (NSRange) minimumRangeofUnit: (NSCalendarUnit) unit
|
||||||
{
|
{
|
||||||
|
#if GS_USE_ICU == 1
|
||||||
|
UCalendarDateFields dateField;
|
||||||
|
NSRange result;
|
||||||
|
UErrorCode err = U_ZERO_ERROR;
|
||||||
|
|
||||||
|
[self _openCalendar];
|
||||||
|
dateField = _NSCalendarUnitToDateField (unit);
|
||||||
|
// We really don't care if there are any errors...
|
||||||
|
result.location =
|
||||||
|
(NSUInteger)ucal_getLimit (_cal, dateField, UCAL_GREATEST_MINIMUM, &err);
|
||||||
|
result.length =
|
||||||
|
(NSUInteger)ucal_getLimit (_cal, dateField, UCAL_LEAST_MAXIMUM, &err)
|
||||||
|
- result.location + 1;
|
||||||
|
// ICU's month is 0-based, while NSCalendar is 1-based
|
||||||
|
if (dateField == UCAL_MONTH)
|
||||||
|
result.location += 1;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
#else
|
||||||
return NSMakeRange (0, 0);
|
return NSMakeRange (0, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSUInteger) ordinalityOfUnit: (NSCalendarUnit) smaller
|
- (NSUInteger) ordinalityOfUnit: (NSCalendarUnit) smaller
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue