Comment detail

指定された日の存在する週 (Nested Flatten)
OSXのCocoaとWindowsのGNUstepで動作確認しています。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#import <Foundation/Foundation.h>

void printWeekdays( unsigned year, unsigned month, unsigned day ) {
	NSCalendarDate* theDay = [NSCalendarDate
			dateWithYear:year month:month day:day hour:0 minute:0 second:0 timeZone:nil];
	int offset = 1 - [theDay dayOfWeek];
	
	for ( int i = 0; i < 5; i++ ) {
		NSCalendarDate* weekday =
				[theDay dateByAddingYears:0 months:0 days:offset + i hours:0 minutes:0 seconds:0];
		NSLog( [weekday descriptionWithCalendarFormat:@"%Y/%m/%d %A"] );
	}
}

int main( int argc, const char** argv ) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	
	printWeekdays( 2000, 1, 1 );
	printWeekdays( 2008, 1, 1 );
	
    [pool release];
    return 0;
}

Index

Feed

Other

Link

Pathtraq

loading...