2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <Foundation/NSArray.h>
23 #import <Foundation/NSCalendarDate.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSKeyValueCoding.h>
26 #import <Foundation/NSString.h>
27 #import <Foundation/NSValue.h>
29 #import <EOControl/EOQualifier.h>
31 #import <NGExtensions/NSCalendarDate+misc.h>
32 #import <NGExtensions/NGCalendarDateRange.h>
34 #import <SoObjects/SOGo/SOGoDateFormatter.h>
36 #import "UIxCalDayView.h"
38 // @interface UIxCalDayView (PrivateAPI)
39 // - (BOOL)isCurrentDateInApt:(id)_apt;
40 // - (NSArray *)_getDatesFrom:(NSCalendarDate *)_from to:(NSCalendarDate *)_to;
43 @implementation UIxCalDayView
47 // [self->currentDate release];
51 // - (void) setCurrentDate: (NSCalendarDate *) _date
53 // ASSIGN(self->currentDate, _date);
56 // - (NSCalendarDate *) currentDate
58 // return self->currentDate;
61 // - (BOOL) isCurrentDateInApt
63 // return [self isCurrentDateInApt: [self appointment]];
66 // - (BOOL) isCurrentDateInApt: (id) _apt
68 // NSCalendarDate *dateStart, *dateEnd, *aptStart, *aptEnd;
69 // NGCalendarDateRange *dateRange, *aptRange;
71 // dateStart = self->currentDate;
72 // dateEnd = [dateStart dateByAddingYears:0 months:0 days:0
73 // hours:1 minutes:0 seconds:0];
74 // dateRange = [NGCalendarDateRange calendarDateRangeWithStartDate:dateStart
76 // aptStart = [self->appointment valueForKey:@"startDate"];
77 // aptEnd = [self->appointment valueForKey:@"endDate"];
78 // aptRange = [NGCalendarDateRange calendarDateRangeWithStartDate:aptStart
81 // return [dateRange doesIntersectWithDateRange:aptRange];
84 // - (NSArray *) dateRange
86 // /* default range is from dayStartHour to dayEndHour. Any values before
87 // or after are also fine */
89 // NSCalendarDate *min, *max;
90 // NSArray *aptDateRanges;
92 // min = [[self startDate] hour:[self dayStartHour] minute:0];
93 // max = [[self startDate] hour:[self dayEndHour] minute:0];
95 // aptDateRanges = [[self appointments] valueForKey: @"startDate"];
96 // if([aptDateRanges count] != 0) {
100 // = [aptDateRanges sortedArrayUsingSelector: @selector(compareAscending:)];
101 // d = [aptDateRanges objectAtIndex:0];
102 // if ([d isDateOnSameDay:min])
103 // min = (NSCalendarDate *)[d earlierDate:min];
104 // d = [aptDateRanges objectAtIndex:[aptDateRanges count] - 1];
105 // if ([d isDateOnSameDay:max])
106 // max = (NSCalendarDate *)[d laterDate:max];
109 // return [self _getDatesFrom:min to:max];
112 // - (NSArray *) _getDatesFrom: (NSCalendarDate *) _from
113 // to: (NSCalendarDate *) _to
115 // NSMutableArray *dates;
116 // unsigned i, count, offset;
118 // offset = [_from hourOfDay];
119 // count = ([_to hourOfDay] + 1) - offset;
120 // dates = [[NSMutableArray alloc] initWithCapacity:count];
121 // for(i = 0; i < count; i++) {
122 // NSCalendarDate *date;
124 // date = [_from hour:offset + i minute:0];
125 // [dates addObject:date];
127 // return [dates autorelease];
132 - (NSDictionary *) dayBeforePrevDayQueryParameters
134 return [self _dateQueryParametersWithOffset: -2];
137 - (NSDictionary *) prevDayQueryParameters
139 return [self _dateQueryParametersWithOffset: -1];
142 - (NSDictionary *) nextDayQueryParameters
144 return [self _dateQueryParametersWithOffset: 1];
147 - (NSDictionary *) dayAfterNextDayQueryParameters
149 return [self _dateQueryParametersWithOffset: 2];
152 - (NSDictionary *) currentDateQueryParameters
154 NSMutableDictionary *qp;
156 NSCalendarDate *date;
158 date = [self selectedDate];
159 hmString = [NSString stringWithFormat:@"%.2d%.2d",
160 [date hourOfDay], [date minuteOfHour]];
161 qp = [[self queryParameters] mutableCopy];
162 [self setSelectedDateQueryParameter:date inDictionary:qp];
163 [qp setObject: hmString forKey:@"hm"];
164 return [qp autorelease];
169 - (NSCalendarDate *) startDate
171 return [[self selectedDate] beginOfDay];
176 // - (NSArray *)allDayApts {
177 // NSCalendarDate *start;
179 // NSMutableArray *filtered;
180 // unsigned i, count;
182 // if (self->allDayApts)
183 // return self->allDayApts;
185 // start = [self startDate];
186 // apts = [self appointments];
187 // filtered = [[NSMutableArray alloc] initWithCapacity:1];
188 // count = [apts count];
189 // for (i = 0; i < count; i++) {
193 // apt = [apts objectAtIndex:i];
194 // bv = [apt valueForKey:@"isallday"];
195 // if ([bv boolValue]) {
196 // [filtered addObject:apt];
199 // NSCalendarDate *aptStartDate;
201 // aptStartDate = [apt valueForKey:@"startDate"];
202 // if([aptStartDate isLessThan:start]) {
203 // [filtered addObject:apt];
208 // ASSIGN(self->allDayApts, filtered);
209 // [filtered release];
210 // return self->allDayApts;
213 // - (BOOL) hasAptsForCurrentDate
215 // return [[self aptsForCurrentDate] count] != 0;
218 - (NSString *) _dayNameWithOffsetFromToday: (int) offset
220 NSCalendarDate *date;
222 date = [[self selectedDate] dateByAddingYears: 0
226 return [self localizedNameForDayOfWeek: [date dayOfWeek]];
229 - (NSString *) dayBeforeYesterdayName
231 return [self _dayNameWithOffsetFromToday: -2];
234 - (NSString *) yesterdayName
236 return [self _dayNameWithOffsetFromToday: -1];
239 - (NSString *) currentDayName
241 return [self _dayNameWithOffsetFromToday: 0];
244 - (NSString *) tomorrowName
246 return [self _dayNameWithOffsetFromToday: 1];
249 - (NSString *) dayAfterTomorrowName
251 return [self _dayNameWithOffsetFromToday: 2];