1 /* iCalDateTime.m - this file is part of SOPE
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/NSString.h>
24 #import <Foundation/NSTimeZone.h>
26 #import "NSCalendarDate+NGCards.h"
27 #import "NSString+NGCards.h"
29 #import "iCalCalendar.h"
30 #import "iCalTimeZone.h"
32 #import "iCalDateTime.h"
34 // static NSTimeZone *localTimeZone = nil;
36 @implementation iCalDateTime
38 // + (void) initialize
40 // if (!localTimeZone)
42 // localTimeZone = [NSTimeZone defaultTimeZone];
43 // [localTimeZone retain];
47 // + (void) setLocalTimeZone: (NSTimeZone *) aTimeZone
49 // [localTimeZone release];
50 // localTimeZone = aTimeZone;
51 // [localTimeZone retain];
54 - (void) setTimeZone: (iCalTimeZone *) iTZ
56 iCalCalendar *calendar;
57 NSCalendarDate *dateTime;
60 dateTime = [self dateTime];
64 = (iCalCalendar *) [self searchParentOfClass: [iCalCalendar class]];
66 [calendar addTimeZone: iTZ];
69 [self setValue: 0 ofAttribute: @"tzid" to: newTZId];
70 [self setDateTime: dateTime];
73 - (iCalTimeZone *) timeZone
75 iCalCalendar *calendar;
77 iCalTimeZone *timeZone;
79 tzId = [self value: 0 ofAttribute: @"tzid"];
81 = (iCalCalendar *) [self searchParentOfClass: [iCalCalendar class]];
82 if ([tzId length] && calendar)
83 timeZone = [calendar timeZoneWithId: tzId];
90 /* TODO: should implement the case where the TZ would be implicitly local
91 (no TZID and no UTC) */
92 - (void) setDateTime: (NSCalendarDate *) dateTime
94 NSCalendarDate *tmpTime;
101 tz = [self timeZone];
103 timeString = [tz dateTimeStringForDate: dateTime];
106 utcTZ = [NSTimeZone timeZoneWithName: @"GMT"];
108 tmpTime = [dateTime copy];
109 [tmpTime setTimeZone: utcTZ];
110 timeString = [NSString stringWithFormat: @"%@Z",
111 [tmpTime iCalFormattedDateTimeString]];
118 [self setValue: 0 to: timeString];
121 - (NSCalendarDate *) dateTime
125 NSCalendarDate *initialDate, *dateTime;
128 date = [self value: 0];
129 iTZ = [self timeZone];
131 dateTime = [iTZ dateForDateTimeString: date];
134 initialDate = [date asCalendarDate];
137 if ([date hasSuffix: @"Z"] || [date hasSuffix: @"z"])
138 dateTime = initialDate;
141 /* same TODO as above */
142 tz = [NSTimeZone defaultTimeZone];
143 dateTime = [initialDate addYear: 0 month: 0 day: 0
145 second: -[tz secondsFromGMT]];