Source

DTFoundation / DTFoundation / NSDate+DTComponentExtension.m

//
//  NSDate+DTExtras.m
//  DTFoundation
//
//  Created by Daniel Tull on 28.07.2009.
//  Copyright 2009 Daniel Tull. All rights reserved.
//

#import "NSDate+DTComponentExtension.h"


@implementation NSDate (DTComponentExtension)

- (NSDateComponents *)gregorianCalendarComponents {
	NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
	NSDateComponents *components = [gregorian components:(NSSecondCalendarUnit | NSMinuteCalendarUnit | NSHourCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSWeekdayOrdinalCalendarUnit | NSWeekCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit | NSEraCalendarUnit) fromDate:self];
	[gregorian release];
	return components;
}

- (NSInteger)second {
	return [[self gregorianCalendarComponents] second];
}

- (NSInteger)minute {
	return [[self gregorianCalendarComponents] minute];
}

- (NSInteger)hour {
	return [[self gregorianCalendarComponents] hour];
}

- (NSInteger)day {
	return [[self gregorianCalendarComponents] day];
}

- (NSInteger)weekday {
	return [[self gregorianCalendarComponents] weekday];
}

- (NSInteger)weekdayOrdinal {
	return [[self gregorianCalendarComponents] weekdayOrdinal];
}

- (NSInteger)week {
	return [[self gregorianCalendarComponents] week];
}

- (NSInteger)month {
	return [[self gregorianCalendarComponents] month];
}

- (NSInteger)year {
	return [[self gregorianCalendarComponents] year];
}

- (NSInteger)era {
	return [[self gregorianCalendarComponents] era];
}

+ (NSDate *)dateWithMonth:(NSInteger)month year:(NSInteger)year {
	return [self dateWithYear:year month:month];
}

+ (NSDate *)dateWithYear:(NSInteger)year {
	NSDateComponents *comps = [[NSDateComponents alloc] init];
	[comps setYear:year];
	NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
	NSDate *date = [gregorian dateFromComponents:comps];
	[comps release];
	[gregorian release];
	return date;
}

+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month {
	NSDateComponents *comps = [[NSDateComponents alloc] init];
	[comps setYear:year];
	[comps setMonth:month];
	NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
	NSDate *date = [gregorian dateFromComponents:comps];
	[comps release];
	[gregorian release];
	return date;
}

+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day {
	NSDateComponents *comps = [[NSDateComponents alloc] init];
	[comps setYear:year];
	[comps setMonth:month];
	[comps setDay:day];
	NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
	NSDate *date = [gregorian dateFromComponents:comps];
	[comps release];
	[gregorian release];
	return date;
}

+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day hour:(NSInteger)hour {
	NSDateComponents *comps = [[NSDateComponents alloc] init];
	[comps setYear:year];
	[comps setMonth:month];
	[comps setDay:day];
	[comps setHour:hour];
	NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
	NSDate *date = [gregorian dateFromComponents:comps];
	[comps release];
	[gregorian release];
	return date;
}

+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day hour:(NSInteger)hour minute:(NSInteger)minute {
	NSDateComponents *comps = [[NSDateComponents alloc] init];
	[comps setYear:year];
	[comps setMonth:month];
	[comps setDay:day];
	[comps setHour:hour];
	[comps setMinute:minute];
	NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
	NSDate *date = [gregorian dateFromComponents:comps];
	[comps release];
	[gregorian release];
	return date;
}

+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day hour:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second {
	NSDateComponents *comps = [[NSDateComponents alloc] init];
	[comps setYear:year];
	[comps setMonth:month];
	[comps setDay:day];
	[comps setHour:hour];
	[comps setMinute:minute];
	[comps setSecond:second];
	NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
	NSDate *date = [gregorian dateFromComponents:comps];
	[comps release];
	[gregorian release];
	return date;
}

@end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.