]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Scheduler/UIxTimeDateControl.m
timezone hack
[scalable-opengroupware.org] / SOGo / UI / Scheduler / UIxTimeDateControl.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include <NGObjWeb/NGObjWeb.h>
24
25 @interface UIxTimeDateControl : WOComponent
26 {
27   NSString *controlID;
28   NSString *label;
29   NSCalendarDate *date;
30   id       hour;
31   id       minute;
32   id       second;
33   id       day;
34   id       month;
35   id       year;
36 }
37
38 - (void)setControlID:(NSString *)_controlID;
39 - (NSString *)controlID;
40 - (void)setLabel:(NSString *)_label;
41 - (NSString *)label;
42 - (void)setDate:(NSCalendarDate *)_date;
43 - (NSCalendarDate *)date;
44
45 - (void)setHour:(id)_hour;
46 - (id)hour;
47 - (void)setMinute:(id)_minute;
48 - (id)minute;
49 - (void)setSecond:(id)_second;
50 - (id)second;
51 - (void)setDay:(id)_day;
52 - (id)day;
53 - (void)setMonth:(id)_month;
54 - (id)month;
55 - (void)setYear:(id)_year;
56 - (id)year;
57
58 - (NSString *)timeID;
59 - (NSString *)dateID;
60
61 - (void)_setDate:(NSCalendarDate *)_date;
62
63 @end
64
65 #include "common.h"
66
67 @implementation UIxTimeDateControl
68
69 static NSTimeZone *MET = nil;
70
71 + (void)initialize {
72     if (MET == nil) {
73         MET = [[NSTimeZone timeZoneWithAbbreviation:@"MET"] retain];
74     }
75 }
76
77 - (void)dealloc {
78   [self->controlID release];
79   [self->label     release];
80   [self->date      release];
81   [self->hour      release];
82   [self->minute    release];
83   [self->second    release];
84   [self->day       release];
85   [self->month     release];
86   [self->year      release];
87   [super dealloc];
88 }
89
90 /* accessors */
91
92 - (void)setControlID:(NSString *)_controlID {
93   ASSIGNCOPY(self->controlID, _controlID);
94 }
95 - (NSString *)controlID {
96   return self->controlID;
97 }
98 - (void)setLabel:(NSString *)_label {
99   ASSIGNCOPY(self->label, _label);
100 }
101 - (NSString *)label {
102   return self->label;
103 }
104 - (void)setDate:(NSCalendarDate *)_date {
105     [self _setDate:_date];
106     [self setHour:[NSNumber numberWithInt:[_date hourOfDay]]];
107     [self setMinute:[NSNumber numberWithInt:[_date minuteOfHour]]];
108     [self setYear:[NSNumber numberWithInt:[_date yearOfCommonEra]]];
109     [self setMonth:[NSNumber numberWithInt:[_date monthOfYear]]];
110     [self setDay:[NSNumber numberWithInt:[_date dayOfMonth]]];
111 }
112 - (void)_setDate:(NSCalendarDate *)_date {
113     ASSIGN(self->date, _date);
114 }
115 - (NSCalendarDate *)date {
116     return self->date;
117 }
118
119 - (void)setHour:(id)_hour {
120     ASSIGN(self->hour, _hour);
121 }
122 - (id)hour {
123     return self->hour;
124 }
125 - (void)setMinute:(id)_minute {
126     ASSIGN(self->minute, _minute);
127 }
128 - (id)minute {
129     return self->minute;
130 }
131 - (void)setSecond:(id)_second {
132     ASSIGN(self->second, _second);
133 }
134 - (id)second {
135     return self->second;
136 }
137
138 - (void)setDay:(id)_day {
139     ASSIGN(self->day, _day);
140 }
141 - (id)day {
142     return self->day;
143 }
144 - (void)setMonth:(id)_month {
145     ASSIGN(self->month, _month);
146 }
147 - (id)month {
148     return self->month;
149 }
150 - (void)setYear:(id)_year {
151     ASSIGN(self->year, _year);
152 }
153 - (id)year {
154     return self->year;
155 }
156
157 - (NSString *)timeID {
158   return [[self controlID] stringByAppendingString:@"_time"];
159 }
160 - (NSString *)dateID {
161   return [[self controlID] stringByAppendingString:@"_date"];
162 }
163
164 /* processing request */
165
166 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
167   NSCalendarDate *d;
168   unsigned _year, _month, _day, _hour, _minute, _second;
169
170   /* call super, so that the form values are applied on the popups */
171   [super takeValuesFromRequest:_rq inContext:_ctx];
172
173   _year  = [[self year] intValue];
174   if(_year == 0)
175       return;
176
177   _month  = [[self month] intValue];
178   _day    = [[self day] intValue];
179   _hour   = [[self hour] intValue];
180   _minute = [[self minute] intValue];
181   _second = [[self second] intValue];
182   d = [NSCalendarDate dateWithYear:_year
183                              month:_month
184                                day:_day
185                               hour:_hour
186                             minute:_minute
187                             second:_second
188                           timeZone:MET];
189   [self debugWithFormat:@"%s setting date:%@", __PRETTY_FUNCTION__, d];
190   [self _setDate:d];
191 }
192
193 @end /* UIxTimeDateControl */