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/NSCalendarDate.h>
23 #import <Foundation/NSUserDefaults.h>
25 #import "SOGoDateFormatter.h"
27 @implementation SOGoDateFormatter
31 if ((self = [super init]))
34 // locale = [_locale retain];
36 // if ([[locale objectForKey:@"NSLocaleCode"] isEqualToString: @"fr"])
37 // shortDateFormat = SOGoDateDMYFormat;
39 // shortDateFormat = SOGoDateISOFormat;
40 shortDateFormat = nil;
50 [longDateFormat release];
51 [shortDateFormat release];
59 - (void) setLocale: (NSDictionary *) newLocale
61 ASSIGN (locale, newLocale);
62 ASSIGN (shortDateFormat, [locale objectForKey: NSShortDateFormatString]);
63 ASSIGN (longDateFormat, [locale objectForKey: NSDateFormatString]);
64 ASSIGN (timeFormat, [locale objectForKey: NSTimeFormatString]);
67 - (void) setShortDateFormat: (NSString *) newFormat
69 ASSIGN (shortDateFormat, newFormat);
72 - (void) setLongDateFormat: (NSString *) newFormat
74 ASSIGN (longDateFormat, newFormat);
77 - (void) setTimeFormat: (NSString *) newFormat
79 ASSIGN (timeFormat, newFormat);
82 // - (void) setFullWeekdayNameAndDetails
84 // auxFormatAction = formatAction;
85 // formatAction = @selector(fullWeekdayNameAndDetailsForDate:);
90 - (NSString *) _date: (NSCalendarDate *) date
91 withFormat: (NSString *) format
93 NSString *formattedDate;
97 = [date descriptionWithCalendarFormat: format locale: locale];
101 return formattedDate;
104 - (NSString *) shortFormattedDate: (NSCalendarDate *) date
106 return [self _date: date withFormat: shortDateFormat];
109 - (NSString *) formattedDate: (NSCalendarDate *) date
111 return [self _date: date withFormat: longDateFormat];
114 - (NSString *) formattedTime: (NSCalendarDate *) date
116 return [self _date: date withFormat: timeFormat];
119 - (NSString *) formattedDateAndTime: (NSCalendarDate *) date
123 format = [NSString stringWithFormat: @"%@ %@ %%Z",
124 longDateFormat, timeFormat];
126 return [self _date: date withFormat: format];
129 - (NSString *) stringForObjectValue: (id) object
131 NSString *formattedString;
133 if ([object isKindOfClass: [NSCalendarDate class]])
134 formattedString = [self formattedDateAndTime: object];
136 formattedString = nil;
138 return formattedString;
143 // - (NSString *)shortDayOfWeek:(int)_day {
144 // return [[locale objectForKey:@"NSShortWeekDayNameArray"]
145 // objectAtIndex:_day];
148 // - (NSString *)fullDayOfWeek:(int)_day {
149 // return [[locale objectForKey:@"NSWeekDayNameArray"]
150 // objectAtIndex:_day];
153 // - (NSString *)shortMonthOfYear:(int)_month {
154 // return [[locale objectForKey:@"NSShortMonthNameArray"]
155 // objectAtIndex:_month - 1];
158 // - (NSString *)fullMonthOfYear:(int)_month {
159 // return [[locale objectForKey:@"NSMonthNameArray"]
160 // objectAtIndex:_month - 1];
166 // - (NSString *) fullWeekdayNameAndDetailsForDate: (NSCalendarDate *) _date
168 // NSMutableString *desc;
172 // desc = [NSMutableString stringWithCapacity:24];
173 // [desc appendString:[self fullDayOfWeek:[_date dayOfWeek]]];
174 // [desc appendString:@", "];
175 // [desc appendString:[self performSelector:auxFormatAction
176 // withObject:_date]];
177 // [desc appendString:@" "];
178 // [desc appendFormat:@"%02d:%02d ", [_date hourOfDay], [_date minuteOfHour]];
179 // [desc appendString:[[_date timeZone] abbreviation]];
187 // - (NSString *) _separatorForFormat: (unsigned int) format
189 // NSString *separator;
191 // switch (format & (3))
193 // case SOGoDateDotFormat:
196 // case SOGoDateDashFormat:
206 // - (NSString *) _dateFormatForDate: (NSCalendarDate *) date
207 // withFormat: (unsigned int) format
208 // andSeparator: (NSString *) separator
210 // NSString *day, *month, *year;
211 // NSString *formattedDate;
213 // day = [NSString stringWithFormat: @"%.2d", [date dayOfMonth]];
214 // month = [NSString stringWithFormat: @"%.2d", [date monthOfYear]];
215 // if (format & SOGoDateTwoDigitsYearFormat)
216 // year = [NSString stringWithFormat: @"%.2d", [date yearOfCommonEra] % 100];
218 // year = [NSString stringWithFormat: @"%.4d", [date yearOfCommonEra]];
220 // if (format & SOGoDateDMYFormat)
221 // formattedDate = [NSString stringWithFormat: @"%@%@%@%@%@",
222 // day, separator, month, separator, year];
223 // else if (format & SOGoDateMDYFormat)
224 // formattedDate = [NSString stringWithFormat: @"%@%@%@%@%@",
225 // month, separator, day, separator, year];
227 // formattedDate = [NSString stringWithFormat: @"%@%@%@%@%@",
228 // year, separator, month, separator, day];
230 // return formattedDate;
233 // - (NSString *) date: (NSCalendarDate *) date
234 // withFormat: (unsigned int) format
236 // NSString *separator;
238 // separator = [self _separatorForFormat: format];
240 // return [self _dateFormatForDate: date
241 // withFormat: format
242 // andSeparator: separator];
245 // - (NSString *) date: (NSCalendarDate *) date
246 // withNSFormat: (NSNumber *) format
248 // return [self date: date withFormat: [format unsignedIntValue]];
251 @end /* SOGoDateFormatter */