#import "Testing.h" #import "ObjectTesting.h" #import #import #import #include #if defined(GS_USE_ICU) #define NSCALENDAR_SUPPORTED GS_USE_ICU #else #define NSCALENDAR_SUPPORTED 1 /* Assume Apple support */ #endif int main() { NSDateComponents *comps; NSCalendar *cal; NSDate *date; NSDate *date2; START_SET("NSCalendar 10.7 features") if (!NSCALENDAR_SUPPORTED) SKIP("NSCalendar not supported\nThe ICU library was not available when GNUstep-base was built") cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; date = [NSDate dateWithString: @"2012-12-31 13:57:00 +0100"]; comps = [cal components: NSYearForWeekOfYearCalendarUnit | NSWeekOfYearCalendarUnit | NSWeekOfMonthCalendarUnit fromDate: date]; PASS([comps weekOfMonth] == 6, "-weekOfMonth returns the correct week"); PASS([comps weekOfYear] == 1, "-weekOfYear returns the correct week"); PASS([comps yearForWeekOfYear] == 2013, "-yearForWeekOfYear returns the correct year"); comps = [[NSDateComponents alloc] init]; [comps setCalendar: cal]; [comps setTimeZone: [NSTimeZone defaultTimeZone]]; [comps setHour: 13]; [comps setMinute: 57]; [comps setDay: 31]; [comps setMonth: 12]; [comps setYear: 2012]; date2 = [comps date]; PASS([date isEqual: date2], "-[NSDateComponents date] returns the correct date"); RELEASE(comps); RELEASE(cal); END_SET("NSCalendar 10.7 features") return 0; }