1 /* UIxCalAptListView.m - this file is part of SOGo
3 * Copyright (C) 2006 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <Foundation/NSDate.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSString.h>
27 #import <NGExtensions/NSCalendarDate+misc.h>
28 #import <Appointments/SOGoAppointmentFolder.h>
30 #import <SOGoUI/SOGoDateFormatter.h>
32 #import "UIxCalAptListView.h"
34 @implementation UIxCalAptListView
38 if ((self = [super init]))
47 - (void) setCurrentAppointment: (NSDictionary *) apt
49 currentAppointment = apt;
52 - (NSDictionary *) currentAppointment
54 return currentAppointment;
57 - (NSCalendarDate *) startDate
59 NSCalendarDate *today;
60 NSString *filterPopup;
64 filterPopup = [self queryParameterForKey: @"filterpopup"];
65 today = [[NSCalendarDate date] beginOfDay];
66 if (!filterPopup || ![filterPopup length])
68 else if ([filterPopup isEqualToString: @"view_selectedday"])
69 startDate = [[self selectedDate] beginOfDay];
70 else if ([filterPopup isEqualToString: @"view_thismonth"])
71 startDate = [today firstDayOfMonth];
72 else if ([filterPopup isEqualToString: @"view_all"])
73 startDate = [NSCalendarDate dateWithTimeIntervalSince1970: 0];
81 - (NSCalendarDate *) endDate
83 NSCalendarDate *today;
84 NSString *filterPopup;
88 filterPopup = [self queryParameterForKey: @"filterpopup"];
90 today = [[NSCalendarDate date] endOfDay];
91 if (!filterPopup || ![filterPopup length]
92 || [filterPopup isEqualToString: @"view_today"])
94 else if ([filterPopup isEqualToString: @"view_all"]
95 || [filterPopup isEqualToString: @"view_future"])
96 endDate = [NSCalendarDate dateWithTimeIntervalSince1970: 0x7fffffff];
97 else if ([filterPopup isEqualToString: @"view_thismonth"])
98 endDate = [today lastDayOfMonth];
99 else if ([filterPopup isEqualToString: @"view_selectedday"])
100 endDate = [[self selectedDate] endOfDay];
101 else if ([filterPopup isEqualToString: @"view_next7"])
102 endDate = [today dateByAddingYears: 0 months: 0 days: 7];
103 else if ([filterPopup isEqualToString: @"view_next14"])
104 endDate = [today dateByAddingYears: 0 months: 0 days: 14];
105 else if ([filterPopup isEqualToString: @"view_next31"])
106 endDate = [today dateByAddingYears: 0 months: 1 days: 0];
114 - (SOGoDateFormatter *) itemDateFormatter
116 SOGoDateFormatter *fmt;
118 fmt = [[SOGoDateFormatter alloc] initWithLocale: [self locale]];
120 [fmt setFullWeekdayNameAndDetails];
125 - (NSString *) currentStartTime
127 NSCalendarDate *date;
129 date = [NSCalendarDate dateWithTimeIntervalSince1970:
130 [[currentAppointment objectForKey: @"startdate"]
132 [date setTimeZone: timeZone];
134 return [[self itemDateFormatter] stringForObjectValue: date];
137 - (NSString *) currentEndTime
139 NSCalendarDate *date;
141 date = [NSCalendarDate dateWithTimeIntervalSince1970:
142 [[currentAppointment objectForKey: @"enddate"]
144 [date setTimeZone: timeZone];
146 return [[self itemDateFormatter] stringForObjectValue: date];
149 - (NSString *) currentLocation
151 return [currentAppointment objectForKey: @"location"];
154 - (NSString *) currentSerialDay
156 NSCalendarDate *date;
159 intDate = [[currentAppointment objectForKey: @"startdate"] intValue];
160 date = [NSCalendarDate dateWithTimeIntervalSince1970: intDate];
161 [date setTimeZone: timeZone];
163 return [NSString stringWithFormat: @"%d%.2d%.2d",
164 [date yearOfCommonEra],
169 - (NSString *) currentSerialHour
171 NSCalendarDate *date;
174 intDate = [[currentAppointment objectForKey: @"startdate"] intValue];
175 date = [NSCalendarDate dateWithTimeIntervalSince1970: intDate];
176 [date setTimeZone: timeZone];
178 return [NSString stringWithFormat: @"%.2d%.2d",
180 [date minuteOfHour]];