// $Id$ #include "UIxCalMonthView.h" #include #include "common.h" @interface NSCalendarDate (UIxCalMonthViewExtensions) - (NSCalendarDate *)dayOfWeeK:(unsigned)_day offsetFromSunday:(unsigned)_offset; - (NSCalendarDate *)sundayOfWeek; @end @implementation NSCalendarDate (UIxCalMonthViewExtensions) - (NSCalendarDate *)dayOfWeeK:(unsigned)_day offsetFromSunday:(unsigned)_offset { unsigned dayOfWeek, distance; /* perform "locale" correction */ dayOfWeek = (7 + [self dayOfWeek] - _offset) % 7; _day = (_day % 7); if(_day == dayOfWeek) return self; distance = _day - dayOfWeek; return [self dateByAddingYears:0 months:0 days:distance]; } /* this implies that monday is the start of week! */ - (NSCalendarDate *)sundayOfWeek { return [self dayOfWeeK:6 offsetFromSunday:1]; } @end @implementation UIxCalMonthView - (NSCalendarDate *)startOfMonth { return [[[super startDate] firstDayOfMonth] beginOfDay]; } - (NSCalendarDate *)startDate { return [[self startOfMonth] mondayOfWeek]; } - (NSCalendarDate *)endDate { NSCalendarDate *date = [self startOfMonth]; date = [date dateByAddingYears:0 months:0 days:[date numberOfDaysInMonth] hours:0 minutes:0 seconds:0]; date = [[date sundayOfWeek] endOfDay]; return date; } /* URLs */ - (NSDictionary *)prevMonthQueryParameters { NSCalendarDate *date; date = [[self startOfMonth] dateByAddingYears:0 months:-1 days:0 hours:0 minutes:0 seconds:0]; return [self queryParametersBySettingSelectedDate:date]; } - (NSDictionary *)nextMonthQueryParameters { NSCalendarDate *date; date = [[self startOfMonth] dateByAddingYears:0 months:1 days:0 hours:0 minutes:0 seconds:0]; return [self queryParametersBySettingSelectedDate:date]; } @end /* UIxCalMonthView */