
#import "Action+Extra.h"

#import "NSDate+Extra.h"


@implementation Machine_Action(Extras)

- (NSString *) noteString
{
	NSError *error;
	NSDictionary *attributes;
	NSAttributedString *astring=[[NSAttributedString alloc] initWithData: [self note] options: nil documentAttributes: &attributes error: &error];
	NSString *result= [astring string];
	[astring autorelease]; //autoreleased incase string depends on astring somehow
	return result;
}

- (void) setNoteString: (NSString *) string
{
	NSRange range;
	NSAttributedString *astring=[[NSAttributedString alloc] initWithString: string attributes: nil];
	range.location=0;
	range.length=[astring length];
	[self setNote:  [astring RTFDFromRange: range documentAttributes: nil]];
	[astring release];
	
}

- (NSDate *) dueDateDate
{
	NSDate *result=[self dueDate];
	if (!result) return [NSCalendarDate calendarDate];
	return result;
}
	
- (NSDate *) dueDateDateOrNil
{
	NSDate *result=[self dueDate];
	return result;
}
	
- (void) setDueDateDate:(NSDate *) value
{
	NSDate *date=[self dueDate];
    if (!value)  { [self setDueDate: nil]; return; }
	if (!date) date=[NSDate date];
	[self setDueDate: [date dateBySettingDate: value]];
}
- (void) setDueDateDateOrNil:(NSDate *) value
{
    [self setDueDateDate: value];
}

- (NSDate *) doDateDate
{
	NSDate *result=[self doDate];
	if (!result) return [NSCalendarDate calendarDate];
	return result;
}

- (NSDate *) doDateDateOrNil
{
	NSDate *result=[self doDate];
	return result;
}

- (void) setDoDateDate:(NSDate *) value
{
	NSDate *date=[self doDate];
    if (!value)  { [self setDoDate: nil]; return; }
	if (!date) date=[NSDate date];
	[self setDoDate: [date dateBySettingDate: value]];
}
- (void) setDoDateDateOrNil:(NSDate *) value
{
	[self setDoDateDate: value];
}

- (NSDate *) startDateDate
{
	NSDate *result=[self startDate];
	if (!result) return [NSCalendarDate calendarDate];
	return result;
}

- (NSDate *) startDateDateOrNil
{
	NSDate *result=[self startDate];
	return result;
}

- (void) setStartDateDate:(NSDate *) value
{
	NSDate *date=[self startDate];
    if (!value)  { [self setStartDate: nil]; return; }
	if (!date) date=[NSDate date];
	[self setStartDate: [date dateBySettingDate: value]];
}
- (void) setStartDateDateOrNil:(NSDate *) value
{
	[self setStartDateDate: value];
}

- (NSDate *) dueDateTime
{
	NSDate *result=[self dueDate];
	if (!result) return [NSCalendarDate calendarDate];
	return result;
}

- (void) setDueDateTime:(NSDate *) value
{
	NSDate *date=[self dueDate];
	if (!date) date=[NSDate date];
	[self setDueDate: [date dateBySettingTime: value]];
}

- (NSDate *) doDateTime
{
	NSDate *result=[self doDate];
	if (!result) return [NSCalendarDate calendarDate];
	return result;
}

- (void) setDoDateTime:(NSDate *) value
{
	NSDate *date=[self doDate];
	if (!date) date=[NSDate date];
	[self setDoDate: [date dateBySettingTime: value]];
}

- (NSDate *) startDateTime
{
	NSDate *result=[self startDate];
	if (!result) return [NSCalendarDate calendarDate];
	return result;
}

- (void) setStartDateTime:(NSDate *) value
{
	NSDate *date=[self startDate];
	if (!date) date=[NSDate date];
	[self setStartDate: [date dateBySettingTime: value]];
}

- (NSDate *) dueDateTimeOrNil
{
	NSDate *result=[self dueDate];
	return result;
}

- (void) setDueDateTimeOrNil:(NSDate *) value
{
	[self setDueDateTime: value];
}

- (NSDate *) doDateTimeOrNil
{
	NSDate *result=[self doDate];
	return result;
}

- (void) setDoDateTimeOrNil:(NSDate *) value
{
	[self setDoDateTime: value];
}

- (NSDate *) startDateTimeOrNil
{
	NSDate *result=[self startDate];
	return result;
}

- (void) setStartDateTimeOrNil:(NSDate *) value
{
	[self setStartDateTime: value];
}

- (int) dueHour
{
	NSDate *date=[self dueDate];
	if (date) return [date hourOfDay];
	return 12; //default is noon?
}

- (void) setDueHour: (int) value
{
	NSDate *date=[self dueDate];
	if (!date) date=[NSDate date];
	[self setDueDate: [date dateBySettingHour: value]];
}

- (int) dueMinute
{
	NSDate *date=[self dueDate];
	if (date) return [date minuteOfHour];
	return 0; //default is 00
}

- (void) setDueMinute: (int) value
{
	NSDate *date=[self dueDate];
	if (!date) date=[NSDate date];
	[self setDueDate: [date dateBySettingMinute: value]];
}

- (int) doHour
{
	NSDate *date=[self doDate];
	if (date) return [date hourOfDay];
	return 12; //default is noon?
}
- (void) setDoHour: (int) value
{
	NSDate *date=[self doDate];
	if (!date) date=[NSDate date];
	[self setDoDate: [date dateBySettingHour: value]];
}

- (int) doMinute
{
	NSDate *date=[self doDate];
	if (date) return [date minuteOfHour];
	return 0; //default is 00
}

- (void) setDoMinute: (int) value
{
	NSDate *date=[self doDate];
	if (!date) date=[NSDate date];
	[self setDoDate: [date dateBySettingMinute: value]];
}

- (int) startHour
{
	NSDate *date=[self startDate];
	if (date) return [date hourOfDay];
	return 12; //default is noon?
}

- (void) setStartHour: (int) value
{
	NSDate *date=[self startDate];
	if (!date) date=[NSDate date];
	[self setStartDate: [date dateBySettingHour: value]];
}

- (int) startMinute
{
	NSDate *date=[self startDate];
	if (date) return [date minuteOfHour];
	return 0; //default is 00
}

- (void) setStartMinute: (int) value
{
	NSDate *date=[self startDate];
	if (!date) date=[NSDate date];
	[self setStartDate: [date dateBySettingMinute: value]];
}

@end