mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
Added copying and coding to NSCalendar. Fixed a few things in NSLocale.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31822 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
797780c433
commit
03c2eaaedb
4 changed files with 95 additions and 9 deletions
|
@ -1,3 +1,9 @@
|
|||
2011-01-01 Stefan Bidigaray <stefanbidi@gmail.com>
|
||||
|
||||
* Headers/Foundation/NSCalendar.h:
|
||||
* Source/NSCalendar.m: Added NSCoding and NSCopying.
|
||||
* Source/NSLocale.m: Implement -isEqual: and do a better job of copying.
|
||||
|
||||
2011-01-01 Stefan Bidigaray <stefanbidi@gmail.com>
|
||||
|
||||
* Headers/Foundation/NSCalendar.h:
|
||||
|
|
|
@ -132,7 +132,7 @@ enum
|
|||
|
||||
|
||||
|
||||
@interface NSCalendar : NSObject
|
||||
@interface NSCalendar : NSObject <NSCoding, NSCopying>
|
||||
{
|
||||
NSString *_identifier;
|
||||
NSString *_localeId;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#import "common.h"
|
||||
#import "Foundation/NSCalendar.h"
|
||||
#import "Foundation/NSCoder.h"
|
||||
#import "Foundation/NSDate.h"
|
||||
#import "Foundation/NSDictionary.h"
|
||||
#import "Foundation/NSLocale.h"
|
||||
|
@ -71,6 +72,8 @@ static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit)
|
|||
- (void) _openCalendar;
|
||||
- (void) _closeCalendar;
|
||||
- (NSString *) _localeIdWithLocale: (NSLocale *) locale;
|
||||
- (NSString *)_localeIdentifier;
|
||||
- (void) _setLocaleIdentifier: (NSString *) identifier;
|
||||
@end
|
||||
|
||||
#define TZ_NAME_LENGTH 1024
|
||||
|
@ -130,6 +133,21 @@ static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit)
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSString *)_localeIdentifier
|
||||
{
|
||||
return _localeId;
|
||||
}
|
||||
|
||||
- (void) _setLocaleIdentifier: (NSString *) identifier
|
||||
{
|
||||
if ([identifier isEqualToString: _localeId])
|
||||
return;
|
||||
|
||||
[self _closeCalendar];
|
||||
RELEASE(_localeId);
|
||||
_localeId = RETAIN(identifier);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSCalendar
|
||||
|
@ -340,12 +358,7 @@ static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit)
|
|||
|
||||
- (void)setLocale: (NSLocale *) locale
|
||||
{
|
||||
if ([[locale localeIdentifier] isEqual: _localeId])
|
||||
return;
|
||||
|
||||
[self _closeCalendar];
|
||||
RELEASE(_localeId);
|
||||
_localeId = RETAIN([self _localeIdWithLocale: locale]);
|
||||
[self _setLocaleIdentifier: [self _localeIdWithLocale: locale]];
|
||||
}
|
||||
|
||||
- (NSUInteger) firstWeekday
|
||||
|
@ -481,6 +494,58 @@ static UCalendarDateFields _NSCalendarUnitToDateField (NSCalendarUnit unit)
|
|||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id) obj
|
||||
{
|
||||
if ([obj isKindOfClass: [self class]])
|
||||
{
|
||||
if (![_identifier isEqual: [obj calendarIdentifier]])
|
||||
return NO;
|
||||
if (![_localeId isEqual: [obj _localeIdentifier]])
|
||||
return NO;
|
||||
if (![_tz isEqual: [obj timeZone]])
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)encoder
|
||||
{
|
||||
[encoder encodeObject: _identifier];
|
||||
[encoder encodeObject: _localeId];
|
||||
[encoder encodeObject: _tz];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)decoder
|
||||
{
|
||||
NSString *s = [decoder decodeObject];
|
||||
|
||||
[self initWithCalendarIdentifier: s];
|
||||
[self _setLocaleIdentifier: [decoder decodeObject]];
|
||||
[self setTimeZone: [decoder decodeObject]];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
NSCalendar *result;
|
||||
|
||||
if (NSShouldRetainWithZone(self, zone))
|
||||
return RETAIN(self);
|
||||
else
|
||||
{
|
||||
result = (NSCalendar *)NSCopyObject(self, 0, zone);
|
||||
result->_identifier = [_identifier copyWithZone: zone];
|
||||
result->_localeId = [_localeId copyWithZone: zone];
|
||||
result->_tz = RETAIN(_tz);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -912,6 +912,14 @@ static NSRecursiveLock *classLock = nil;
|
|||
return _localeId;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id) obj
|
||||
{
|
||||
if ([obj isKindOfClass: [self class]])
|
||||
return [_localeId isEqual: [obj localeIdentifier]];
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_localeId);
|
||||
|
@ -933,10 +941,17 @@ static NSRecursiveLock *classLock = nil;
|
|||
|
||||
- (id) copyWithZone: (NSZone *) zone
|
||||
{
|
||||
NSLocale *result;
|
||||
|
||||
if (NSShouldRetainWithZone(self, zone))
|
||||
return RETAIN(self);
|
||||
result = RETAIN(self);
|
||||
else
|
||||
return NSCopyObject(self, 0, zone);
|
||||
{
|
||||
result = (NSLocale *)NSCopyObject(self, 0, zone);
|
||||
result->_localeId = [_localeId copyWithZone: zone];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue