/* individual values */
id startDateHour;
id startDateMinute;
+ id endDateHour;
+ id endDateMinute;
+
id startDateDay;
id startDateMonth;
id startDateYear;
-
- id endDateHour;
- id endDateMinute;
id endDateDay;
id endDateMonth;
id endDateYear;
}
- (void)setStartDateHour:(id)_startDateHour {
- ASSIGN(self->startDateHour, _startDateHour);
+ ASSIGN(self->startDateHour, _startDateHour);
}
- (id)startDateHour {
- return self->startDateHour;
+ return self->startDateHour;
}
- (void)setStartDateMinute:(id)_startDateMinute {
- ASSIGN(self->startDateMinute, _startDateMinute);
+ ASSIGN(self->startDateMinute, _startDateMinute);
}
- (id)startDateMinute {
- return self->startDateMinute;
+ return self->startDateMinute;
}
- (void)setStartDateDay:(id)_startDateDay {
- ASSIGN(self->startDateDay, _startDateDay);
+ ASSIGN(self->startDateDay, _startDateDay);
}
- (id)startDateDay {
- return self->startDateDay;
+ return self->startDateDay;
}
- (void)setStartDateMonth:(id)_startDateMonth {
- ASSIGN(self->startDateMonth, _startDateMonth);
+ ASSIGN(self->startDateMonth, _startDateMonth);
}
- (id)startDateMonth {
- return self->startDateMonth;
+ return self->startDateMonth;
}
- (void)setStartDateYear:(id)_startDateYear {
- ASSIGN(self->startDateYear, _startDateYear);
+ ASSIGN(self->startDateYear, _startDateYear);
}
- (id)startDateYear {
- return self->startDateYear;
+ return self->startDateYear;
}
- (void)setEndDateHour:(id)_endDateHour {
- ASSIGN(self->endDateHour, _endDateHour);
+ ASSIGN(self->endDateHour, _endDateHour);
}
- (id)endDateHour {
- return self->endDateHour;
+ return self->endDateHour;
}
- (void)setEndDateMinute:(id)_endDateMinute {
- ASSIGN(self->endDateMinute, _endDateMinute);
+ ASSIGN(self->endDateMinute, _endDateMinute);
}
- (id)endDateMinute {
- return self->endDateMinute;
+ return self->endDateMinute;
}
- (void)setEndDateDay:(id)_endDateDay {
- ASSIGN(self->endDateDay, _endDateDay);
+ ASSIGN(self->endDateDay, _endDateDay);
}
- (id)endDateDay {
- return self->endDateDay;
+ return self->endDateDay;
}
- (void)setEndDateMonth:(id)_endDateMonth {
- ASSIGN(self->endDateMonth, _endDateMonth);
+ ASSIGN(self->endDateMonth, _endDateMonth);
}
- (id)endDateMonth {
- return self->endDateMonth;
+ return self->endDateMonth;
}
- (void)setEndDateYear:(id)_endDateYear {
- ASSIGN(self->endDateYear, _endDateYear);
+ ASSIGN(self->endDateYear, _endDateYear);
}
- (id)endDateYear {
- return self->endDateYear;
+ return self->endDateYear;
}
- (void)setStartDate:(NSCalendarDate *)_date {
}
- (NSCalendarDate *)startDate {
return [NSCalendarDate dateWithYear:[[self startDateYear] intValue]
- month:[[self startDateMonth] intValue]
- day:[[self startDateDay] intValue]
- hour:[[self startDateHour] intValue]
- minute:[[self startDateMinute] intValue]
- second:0
- timeZone:[self viewTimeZone]];
+ month:[[self startDateMonth] intValue]
+ day:[[self startDateDay] intValue]
+ hour:[[self startDateHour] intValue]
+ minute:[[self startDateMinute] intValue]
+ second:0
+ timeZone:[self viewTimeZone]];
}
- (void)setEndDate:(NSCalendarDate *)_date {
[self setEndDateHour:[NSNumber numberWithInt:[_date hourOfDay]]];
[self setEndDateYear:[NSNumber numberWithInt:[_date yearOfCommonEra]]];
}
- (NSCalendarDate *)endDate {
- return [NSCalendarDate dateWithYear:[[self endDateYear] intValue]
- month:[[self endDateMonth] intValue]
- day:[[self endDateDay] intValue]
- hour:[[self endDateHour] intValue]
- minute:[[self endDateMinute] intValue]
- second:59
- timeZone:[self viewTimeZone]];
+ return [NSCalendarDate dateWithYear:[[self endDateYear] intValue]
+ month:[[self endDateMonth] intValue]
+ day:[[self endDateDay] intValue]
+ hour:[[self endDateHour] intValue]
+ minute:[[self endDateMinute] intValue]
+ second:59
+ timeZone:[self viewTimeZone]];
}
- (void)setDuration:(id)_duration {
- (NSString *)itemDurationText {
// TODO: use a formatter
+ // TODO: localize
switch ([[self item] intValue]) {
case 30: return @"30 minutes";
case 60: return @"1 hour";
case 120: return @"2 hours";
+ case 240: return @"4 hours";
+ case 480: return @"8 hours";
default:
return [NSString stringWithFormat:@"%@ minutes", [self item]];
}
unsigned lStartHour = 9, lEndHour = 17, i;
NSMutableArray *ma;
+ lStartHour = [[self startDateHour] intValue];
+ lEndHour = [[self endDateHour] intValue];
+ if (lStartHour < 1) lStartHour = 1;
+ if (lEndHour < lStartHour) lEndHour = lStartHour + 1;
+
ma = [NSMutableArray arrayWithCapacity:lEndHour - lStartHour + 2];
for (i = lStartHour; i <= lEndHour; i++)
[ma addObject:[NSNumber numberWithInt:i]];
- (NSArray *)days {
// TODO: from startdate to enddate
- return [NSArray arrayWithObjects:@"2004-08-15", nil];
+ NSMutableArray *ma;
+ NSCalendarDate *base, *stop, *current;
+
+ base = [NSCalendarDate dateWithYear:[[self startDateYear] intValue]
+ month:[[self startDateMonth] intValue]
+ day:[[self startDateDay] intValue]
+ hour:12 minute:0 second:0
+ timeZone:[self viewTimeZone]];
+ stop = [NSCalendarDate dateWithYear:[[self endDateYear] intValue]
+ month:[[self endDateMonth] intValue]
+ day:[[self endDateDay] intValue]
+ hour:12 minute:0 second:0
+ timeZone:[self viewTimeZone]];
+
+ ma = [NSMutableArray arrayWithCapacity:16];
+
+ current = base;
+ while ([current compare:stop] != NSOrderedDescending) {
+ [ma addObject:current];
+
+ /* Note: remember the timezone behaviour of the method below! */
+ current = [current dateByAddingYears:0 months:0 days:1];
+ }
+ return ma;
}
- (NSArray *)durationSteps {
// TODO: make configurable
- return [NSArray arrayWithObjects:@"30", @"60", @"120", nil];
+ return [NSArray arrayWithObjects:
+ @"30", @"60", @"120", @"240", @"480", nil];
}
/* slots */
now = [NSCalendarDate date];
+ [self setDuration:@"120"]; /* 1 hour as default */
[self setStartDate:[now hour:9 minute:0]];
[self setEndDate:[now hour:18 minute:0]];