mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Add missing NSDateComponents methods.
This commit is contained in:
parent
a9767cdff7
commit
82e9ddc21f
2 changed files with 128 additions and 1 deletions
|
@ -129,7 +129,7 @@ enum
|
|||
NSCalendarUnitWeekOfMonth = (1UL << 12),
|
||||
NSCalendarUnitWeekOfYear = (1UL << 13),
|
||||
NSCalendarUnitYearForWeekOfYear = (1UL << 14),
|
||||
NSCalendarUnitNanosecond = (1 << 15), // FIXME: unimplemented
|
||||
NSCalendarUnitNanosecond = (1 << 15),
|
||||
NSCalendarUnitCalendar = (1 << 20), // FIXME: unimplemented
|
||||
NSCalendarUnitTimeZone = (1 << 21) // FIXME: unimplemented
|
||||
#endif
|
||||
|
@ -227,6 +227,7 @@ enum
|
|||
* yearForWeekOfYear is 2013, since it's already week 1 in 2013.
|
||||
*/
|
||||
- (NSInteger) yearForWeekOfYear;
|
||||
- (NSInteger) nanosecond;
|
||||
|
||||
/** Sets the number of the week in this month. */
|
||||
- (void) setWeekOfMonth: (NSInteger) v;
|
||||
|
@ -241,8 +242,22 @@ enum
|
|||
* See the explanation at <code>-yearForWeekOfYear</code>.
|
||||
*/
|
||||
- (void) setYearForWeekOfYear: (NSInteger) v;
|
||||
- (void) setNanosecond: (NSInteger) v;
|
||||
|
||||
#endif
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_8, GS_API_LATEST)
|
||||
- (BOOL) leapMonth;
|
||||
- (void) setLeapMonth: (BOOL) v;
|
||||
#endif
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_9, GS_API_LATEST)
|
||||
- (BOOL) isValidDate;
|
||||
- (BOOL) isValidDateInCalendar: (NSCalendar *) calendar;
|
||||
- (NSInteger) valueForComponent: (NSCalendarUnit) unit;
|
||||
- (void) setValue: (NSInteger) value
|
||||
forComponent: (NSCalendarUnit) unit;
|
||||
#endif
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -843,6 +843,8 @@ typedef struct {
|
|||
NSInteger quarter;
|
||||
NSInteger weekOfMonth;
|
||||
NSInteger yearForWeekOfYear;
|
||||
BOOL leapMonth;
|
||||
NSInteger nanosecond;
|
||||
NSCalendar *cal;
|
||||
NSTimeZone *tz;
|
||||
} DateComp;
|
||||
|
@ -880,6 +882,8 @@ typedef struct {
|
|||
my->quarter = NSDateComponentUndefined;
|
||||
my->weekOfMonth = NSDateComponentUndefined;
|
||||
my->yearForWeekOfYear = NSDateComponentUndefined;
|
||||
my->leapMonth = NO;
|
||||
my->nanosecond = NSDateComponentUndefined;
|
||||
my->cal = NULL;
|
||||
my->tz = NULL;
|
||||
}
|
||||
|
@ -921,6 +925,11 @@ typedef struct {
|
|||
return my->second;
|
||||
}
|
||||
|
||||
- (NSInteger) nanosecond
|
||||
{
|
||||
return my->nanosecond;
|
||||
}
|
||||
|
||||
- (NSInteger) week
|
||||
{
|
||||
return my->week;
|
||||
|
@ -956,6 +965,11 @@ typedef struct {
|
|||
return my->yearForWeekOfYear;
|
||||
}
|
||||
|
||||
- (BOOL) leapMonth
|
||||
{
|
||||
return my->leapMonth;
|
||||
}
|
||||
|
||||
- (NSCalendar *) calendar
|
||||
{
|
||||
return my->cal;
|
||||
|
@ -1013,6 +1027,11 @@ typedef struct {
|
|||
my->second = v;
|
||||
}
|
||||
|
||||
- (void) setNanosecond: (NSInteger) v
|
||||
{
|
||||
my->nanosecond = v;
|
||||
}
|
||||
|
||||
- (void) setWeek: (NSInteger) v
|
||||
{
|
||||
my->week = v;
|
||||
|
@ -1048,6 +1067,11 @@ typedef struct {
|
|||
my->yearForWeekOfYear = v;
|
||||
}
|
||||
|
||||
- (void) setLeapMonth: (BOOL) v
|
||||
{
|
||||
my->leapMonth = v;
|
||||
}
|
||||
|
||||
- (void) setCalendar: (NSCalendar *) cal
|
||||
{
|
||||
ASSIGN(my->cal, cal);
|
||||
|
@ -1058,6 +1082,94 @@ typedef struct {
|
|||
ASSIGN(my->tz, tz);
|
||||
}
|
||||
|
||||
- (BOOL) isValidDate
|
||||
{
|
||||
if (my->cal == nil)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
return [self isValidDateInCalendar: my->cal];
|
||||
}
|
||||
|
||||
- (BOOL) isValidDateInCalendar: (NSCalendar *) calendar
|
||||
{
|
||||
return [calendar dateFromComponents: self] != nil;
|
||||
}
|
||||
|
||||
- (NSInteger) valueForComponent: (NSCalendarUnit) unit
|
||||
{
|
||||
switch (unit)
|
||||
{
|
||||
case NSCalendarUnitEra: return my->era;
|
||||
case NSCalendarUnitYear: return my->year;
|
||||
case NSCalendarUnitMonth: return my->month;
|
||||
case NSCalendarUnitDay: return my->day;
|
||||
case NSCalendarUnitHour: return my->hour;
|
||||
case NSCalendarUnitMinute: return my->minute;
|
||||
case NSCalendarUnitSecond: return my->second;
|
||||
case NSCalendarUnitWeekday: return my->weekday;
|
||||
case NSCalendarUnitWeekdayOrdinal: return my->weekdayOrdinal;
|
||||
case NSCalendarUnitQuarter: return my->quarter;
|
||||
case NSCalendarUnitWeekOfMonth: return my->weekOfMonth;
|
||||
case NSCalendarUnitWeekOfYear: return my->week;
|
||||
case NSCalendarUnitYearForWeekOfYear: return my->yearForWeekOfYear;
|
||||
case NSCalendarUnitNanosecond: return my->nanosecond;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setValue: (NSInteger) value
|
||||
forComponent: (NSCalendarUnit) unit
|
||||
{
|
||||
switch (unit)
|
||||
{
|
||||
case NSCalendarUnitEra:
|
||||
my->era = value;
|
||||
break;
|
||||
case NSCalendarUnitYear:
|
||||
my->year = value;
|
||||
break;
|
||||
case NSCalendarUnitMonth:
|
||||
my->month = value;
|
||||
break;
|
||||
case NSCalendarUnitDay:
|
||||
my->day = value;
|
||||
break;
|
||||
case NSCalendarUnitHour:
|
||||
my->hour = value;
|
||||
break;
|
||||
case NSCalendarUnitMinute:
|
||||
my->minute = value;
|
||||
break;
|
||||
case NSCalendarUnitSecond:
|
||||
my->second = value;
|
||||
break;
|
||||
case NSCalendarUnitWeekday:
|
||||
my->weekday = value;
|
||||
break;
|
||||
case NSCalendarUnitWeekdayOrdinal:
|
||||
my->weekdayOrdinal = value;
|
||||
break;
|
||||
case NSCalendarUnitQuarter:
|
||||
my->quarter = value;
|
||||
break;
|
||||
case NSCalendarUnitWeekOfMonth:
|
||||
my->weekOfMonth = value;
|
||||
break;
|
||||
case NSCalendarUnitWeekOfYear:
|
||||
my->week = value;
|
||||
break;
|
||||
case NSCalendarUnitYearForWeekOfYear:
|
||||
my->yearForWeekOfYear = value;
|
||||
break;
|
||||
case NSCalendarUnitNanosecond:
|
||||
my->nanosecond = value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
if (NSShouldRetainWithZone(self, zone))
|
||||
|
|
Loading…
Reference in a new issue