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 #include "SOGoDateFormatter.h"
25 @implementation SOGoDateFormatter
27 - (id)initWithLocale:(NSDictionary *)_locale {
28 if ((self = [super init])) {
29 self->locale = [_locale retain];
31 if ([[self->locale objectForKey:@"NSLocaleCode"] isEqualToString:@"fr"])
32 [self setFrenchDateFormat];
34 [self setISODateFormat];
40 [self->locale release];
46 - (void)setISODateFormat {
47 self->formatAction = @selector(isoDateFormatForDate:);
50 - (void)setFrenchDateFormat {
51 self->formatAction = @selector(frenchDateFormatForDate:);
54 - (void)setFullWeekdayNameAndDetails {
55 self->auxFormatAction = self->formatAction;
56 self->formatAction = @selector(fullWeekdayNameAndDetailsForDate:);
61 - (NSString *)stringForObjectValue:(id)_obj {
62 return [self performSelector:self->formatAction
68 - (NSString *)shortDayOfWeek:(int)_day {
69 return [[self->locale objectForKey:@"NSShortWeekDayNameArray"]
73 - (NSString *)fullDayOfWeek:(int)_day {
74 return [[self->locale objectForKey:@"NSWeekDayNameArray"]
78 - (NSString *)shortMonthOfYear:(int)_month {
79 return [[self->locale objectForKey:@"NSShortMonthNameArray"]
80 objectAtIndex:_month - 1];
83 - (NSString *)fullMonthOfYear:(int)_month {
84 return [[self->locale objectForKey:@"NSMonthNameArray"]
85 objectAtIndex:_month - 1];
91 - (NSString *)isoDateFormatForDate:(NSCalendarDate *)_date {
94 if (_date == nil) return nil;
95 snprintf(buf, sizeof(buf),
97 [_date yearOfCommonEra], [_date monthOfYear], [_date dayOfMonth]);
98 return [NSString stringWithCString:buf];
101 - (NSString *)frenchDateFormatForDate:(NSCalendarDate *)_date {
104 if (_date == nil) return nil;
105 snprintf(buf, sizeof(buf),
107 [_date dayOfMonth], [_date monthOfYear], [_date yearOfCommonEra]);
108 return [NSString stringWithCString:buf];
111 - (NSString *)fullWeekdayNameAndDetailsForDate:(NSCalendarDate *)_date {
112 NSMutableString *desc;
114 if (_date == nil) return nil;
116 desc = [NSMutableString stringWithCapacity:24];
117 [desc appendString:[self fullDayOfWeek:[_date dayOfWeek]]];
118 [desc appendString:@", "];
119 [desc appendString:[self performSelector:self->auxFormatAction
121 [desc appendString:@" "];
122 [desc appendFormat:@"%02d:%02d ", [_date hourOfDay], [_date minuteOfHour]];
123 [desc appendString:[[_date timeZone] abbreviation]];
127 @end /* SOGoDateFormatter */