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 @interface SOGoDateFormatter (PrivateAPI)
26 - (NSString *)shortDayOfWeek:(int)_day;
27 - (NSString *)fullDayOfWeek:(int)_day;
28 - (NSString *)shortMonthOfYear:(int)_month;
29 - (NSString *)fullMonthOfYear:(int)_month;
31 - (NSString *)isoDateFormatForDate:(NSCalendarDate *)_date;
32 - (NSString *)fullWeekdayNameAndDetailsForDate:(NSCalendarDate *)_date;
35 @implementation SOGoDateFormatter
37 - (id)initWithLocale:(NSDictionary *)_locale {
38 if ((self = [super init])) {
39 self->locale = [_locale retain];
40 [self setISODateFormat];
46 [self->locale release];
52 - (void)setISODateFormat {
53 self->formatAction = @selector(isoDateFormatForDate:);
56 - (void)setFullWeekdayNameAndDetails {
57 self->formatAction = @selector(fullWeekdayNameAndDetailsForDate:);
62 - (NSString *)stringForObjectValue:(id)_obj {
63 return [self performSelector:self->formatAction
69 - (NSString *)shortDayOfWeek:(int)_day {
70 return [[self->locale objectForKey:@"NSShortWeekDayNameArray"]
74 - (NSString *)fullDayOfWeek:(int)_day {
75 return [[self->locale objectForKey:@"NSWeekDayNameArray"]
79 - (NSString *)shortMonthOfYear:(int)_month {
80 return [[self->locale objectForKey:@"NSShortMonthNameArray"]
81 objectAtIndex:_month - 1];
84 - (NSString *)fullMonthOfYear:(int)_month {
85 return [[self->locale objectForKey:@"NSMonthNameArray"]
86 objectAtIndex:_month - 1];
92 - (NSString *)isoDateFormatForDate:(NSCalendarDate *)_date {
93 return [NSString stringWithFormat:@"%04d-%02d-%02d",
94 [_date yearOfCommonEra],
99 - (NSString *)fullWeekdayNameAndDetailsForDate:(NSCalendarDate *)_date {
100 NSMutableString *desc;
102 desc = [NSMutableString stringWithCapacity:24];
103 [desc appendString:[self fullDayOfWeek:[_date dayOfWeek]]];
104 [desc appendString:@", "];
105 [desc appendString:[self isoDateFormatForDate:_date]];
106 [desc appendString:@" "];
107 [desc appendFormat:@"%02d:%02d ", [_date hourOfDay], [_date minuteOfHour]];
108 [desc appendString:[[_date timeZone] abbreviation]];
112 @end /* SOGoDateFormatter */