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/NSDictionary.h>
23 #import <Foundation/NSCalendarDate.h>
24 #import <Foundation/NSUserDefaults.h>
26 #import "SOGoDateFormatter.h"
28 @implementation SOGoDateFormatter
32 if ((self = [super init]))
35 // locale = [_locale retain];
37 // if ([[locale objectForKey:@"NSLocaleCode"] isEqualToString: @"fr"])
38 // shortDateFormat = SOGoDateDMYFormat;
40 // shortDateFormat = SOGoDateISOFormat;
41 shortDateFormat = nil;
51 [longDateFormat release];
52 [shortDateFormat release];
60 - (void) setLocale: (NSDictionary *) newLocale
62 ASSIGN (locale, newLocale);
63 ASSIGN (shortDateFormat, [locale objectForKey: NSShortDateFormatString]);
64 ASSIGN (longDateFormat, [locale objectForKey: NSDateFormatString]);
65 ASSIGN (timeFormat, [locale objectForKey: NSTimeFormatString]);
68 - (void) setShortDateFormat: (NSString *) newFormat
70 ASSIGN (shortDateFormat, newFormat);
73 - (void) setLongDateFormat: (NSString *) newFormat
75 ASSIGN (longDateFormat, newFormat);
78 - (void) setTimeFormat: (NSString *) newFormat
80 ASSIGN (timeFormat, newFormat);
83 // - (void) setFullWeekdayNameAndDetails
85 // auxFormatAction = formatAction;
86 // formatAction = @selector(fullWeekdayNameAndDetailsForDate:);
91 - (NSString *) _date: (NSCalendarDate *) date
92 withFormat: (NSString *) format
94 NSString *formattedDate;
98 = [date descriptionWithCalendarFormat: format locale: locale];
102 return formattedDate;
105 - (NSString *) shortFormattedDate: (NSCalendarDate *) date
107 return [self _date: date withFormat: shortDateFormat];
110 - (NSString *) formattedDate: (NSCalendarDate *) date
112 return [self _date: date withFormat: longDateFormat];
115 - (NSString *) formattedTime: (NSCalendarDate *) date
117 return [self _date: date withFormat: timeFormat];
120 - (NSString *) formattedDateAndTime: (NSCalendarDate *) date
124 format = [NSString stringWithFormat: @"%@ %@ %%Z",
125 longDateFormat, timeFormat];
127 return [self _date: date withFormat: format];
130 - (NSString *) stringForObjectValue: (id) object
132 NSString *formattedString;
134 if ([object isKindOfClass: [NSCalendarDate class]])
135 formattedString = [self formattedDateAndTime: object];
137 formattedString = nil;
139 return formattedString;
144 // - (NSString *)shortDayOfWeek:(int)_day {
145 // return [[locale objectForKey:@"NSShortWeekDayNameArray"]
146 // objectAtIndex:_day];
149 // - (NSString *)fullDayOfWeek:(int)_day {
150 // return [[locale objectForKey:@"NSWeekDayNameArray"]
151 // objectAtIndex:_day];
154 // - (NSString *)shortMonthOfYear:(int)_month {
155 // return [[locale objectForKey:@"NSShortMonthNameArray"]
156 // objectAtIndex:_month - 1];
159 // - (NSString *)fullMonthOfYear:(int)_month {
160 // return [[locale objectForKey:@"NSMonthNameArray"]
161 // objectAtIndex:_month - 1];
167 // - (NSString *) fullWeekdayNameAndDetailsForDate: (NSCalendarDate *) _date
169 // NSMutableString *desc;
173 // desc = [NSMutableString stringWithCapacity:24];
174 // [desc appendString:[self fullDayOfWeek:[_date dayOfWeek]]];
175 // [desc appendString:@", "];
176 // [desc appendString:[self performSelector:auxFormatAction
177 // withObject:_date]];
178 // [desc appendString:@" "];
179 // [desc appendFormat:@"%02d:%02d ", [_date hourOfDay], [_date minuteOfHour]];
180 // [desc appendString:[[_date timeZone] abbreviation]];
188 // - (NSString *) _separatorForFormat: (unsigned int) format
190 // NSString *separator;
192 // switch (format & (3))
194 // case SOGoDateDotFormat:
197 // case SOGoDateDashFormat:
207 // - (NSString *) _dateFormatForDate: (NSCalendarDate *) date
208 // withFormat: (unsigned int) format
209 // andSeparator: (NSString *) separator
211 // NSString *day, *month, *year;
212 // NSString *formattedDate;
214 // day = [NSString stringWithFormat: @"%.2d", [date dayOfMonth]];
215 // month = [NSString stringWithFormat: @"%.2d", [date monthOfYear]];
216 // if (format & SOGoDateTwoDigitsYearFormat)
217 // year = [NSString stringWithFormat: @"%.2d", [date yearOfCommonEra] % 100];
219 // year = [NSString stringWithFormat: @"%.4d", [date yearOfCommonEra]];
221 // if (format & SOGoDateDMYFormat)
222 // formattedDate = [NSString stringWithFormat: @"%@%@%@%@%@",
223 // day, separator, month, separator, year];
224 // else if (format & SOGoDateMDYFormat)
225 // formattedDate = [NSString stringWithFormat: @"%@%@%@%@%@",
226 // month, separator, day, separator, year];
228 // formattedDate = [NSString stringWithFormat: @"%@%@%@%@%@",
229 // year, separator, month, separator, day];
231 // return formattedDate;
234 // - (NSString *) date: (NSCalendarDate *) date
235 // withFormat: (unsigned int) format
237 // NSString *separator;
239 // separator = [self _separatorForFormat: format];
241 // return [self _dateFormatForDate: date
242 // withFormat: format
243 // andSeparator: separator];
246 // - (NSString *) date: (NSCalendarDate *) date
247 // withNSFormat: (NSNumber *) format
249 // return [self date: date withFormat: [format unsignedIntValue]];
252 @end /* SOGoDateFormatter */