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
23 #include <SOGoUI/UIxComponent.h>
25 @interface UIxCalDateLabel : UIxComponent
28 NSCalendarDate *startDate;
29 NSCalendarDate *endDate;
32 - (NSString *)dayLabel;
33 - (NSString *)weekLabel;
34 - (NSString *)monthLabel;
35 - (NSString *)yearLabel;
41 @implementation UIxCalDateLabel
44 [self->selection release];
45 [self->startDate release];
46 [self->endDate release];
52 - (void)setSelection:(NSString *)_selection {
53 ASSIGNCOPY(self->selection, _selection);
55 - (NSString *)selection {
56 return self->selection;
59 - (void)setStartDate:(NSCalendarDate *)_date {
60 ASSIGN(self->startDate, _date);
62 - (NSCalendarDate *)startDate {
63 return self->startDate;
66 - (void)setEndDate:(NSCalendarDate *)_date {
67 ASSIGN(self->endDate, _date);
69 - (NSCalendarDate *)endDate {
74 NSString *key = [self selection];
76 if([key isEqualToString:@"day"])
77 return [self dayLabel];
78 if ([key isEqualToString:@"week"])
79 return [self weekLabel];
80 if ([key isEqualToString:@"month"])
81 return [self monthLabel];
82 return [self yearLabel];
85 - (NSString *)dayLabel {
88 fmt = [self labelForKey:@"dayLabelFormat"];
89 return [self->startDate descriptionWithCalendarFormat:fmt];
92 - (NSString *)weekLabel {
95 label = [self localizedNameForMonthOfYear:[self->startDate monthOfYear]];
96 label = [NSString stringWithFormat:@"%@ %d",
98 [self->startDate yearOfCommonEra]];
99 if ([self->startDate monthOfYear] != [self->endDate monthOfYear]) {
102 le = [self localizedNameForMonthOfYear:[self->endDate monthOfYear]];
103 label = [NSString stringWithFormat:@"<nobr>%@ / %@ %d</nobr>",
105 [self->endDate yearOfCommonEra]];
110 - (NSString *)monthLabel {
114 diff = [self->startDate monthsBetweenDate:self->endDate];
116 l = [self localizedNameForMonthOfYear:[self->startDate monthOfYear]];
119 NSCalendarDate *date;
121 date = [self->startDate dateByAddingYears:0 months:0 days:15];
122 l = [self localizedNameForMonthOfYear:[date monthOfYear]];
124 return [NSString stringWithFormat:@"%@ %d",
125 l, [self->startDate yearOfCommonEra]];
128 - (NSString *)yearLabel {
129 return [NSString stringWithFormat:@"%d",
130 [self->startDate yearOfCommonEra]];
133 @end /* UIxCalDateLabel */