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;
40 #include <NGCards/NGCards.h>
42 @implementation UIxCalDateLabel
45 [self->selection release];
46 [self->startDate release];
47 [self->endDate release];
53 - (void)setSelection:(NSString *)_selection {
54 ASSIGNCOPY(self->selection, _selection);
56 - (NSString *)selection {
57 return self->selection;
60 - (void)setStartDate:(NSCalendarDate *)_date {
61 ASSIGN(self->startDate, _date);
63 - (NSCalendarDate *)startDate {
64 return self->startDate;
67 - (void)setEndDate:(NSCalendarDate *)_date {
68 ASSIGN(self->endDate, _date);
70 - (NSCalendarDate *)endDate {
75 NSString *key = [self selection];
77 if([key isEqualToString:@"day"])
78 return [self dayLabel];
79 if ([key isEqualToString:@"week"])
80 return [self weekLabel];
81 if ([key isEqualToString:@"month"])
82 return [self monthLabel];
83 return [self yearLabel];
86 - (NSString *)dayLabel {
89 fmt = [self labelForKey:@"dayLabelFormat"];
90 return [self->startDate descriptionWithCalendarFormat:fmt];
93 - (NSString *)weekLabel {
96 if ([self->startDate monthOfYear] == [self->endDate monthOfYear])
97 label = [NSString stringWithFormat:@"%@ %d",
98 [self localizedNameForMonthOfYear: [self->startDate monthOfYear]],
99 [self->startDate yearOfCommonEra]];
102 le = [self localizedNameForMonthOfYear:[self->endDate monthOfYear]];
103 label = [NSString stringWithFormat:@"<nobr>%@ / %@ %d</nobr>",
105 [self->endDate yearOfCommonEra]];
111 - (NSString *)monthLabel {
115 diff = [self->startDate monthsBetweenDate:self->endDate];
117 l = [self localizedNameForMonthOfYear:[self->startDate monthOfYear]];
120 NSCalendarDate *date;
122 date = [self->startDate dateByAddingYears:0 months:0 days:15];
123 l = [self localizedNameForMonthOfYear:[date monthOfYear]];
125 return [NSString stringWithFormat:@"%@ %d",
126 l, [self->startDate yearOfCommonEra]];
129 - (NSString *)yearLabel {
130 return [NSString stringWithFormat:@"%d",
131 [self->startDate yearOfCommonEra]];
134 @end /* UIxCalDateLabel */