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>
24 #import <NGCards/NSCalendarDate+ICal.h>
25 #import <NGExtensions/NSCalendarDate+misc.h>
27 #import <SOGoUI/UIxComponent.h>
29 @interface UIxCalDateLabel : UIxComponent
32 NSCalendarDate *startDate;
33 NSCalendarDate *endDate;
36 - (NSString *)dayLabel;
37 - (NSString *)weekLabel;
38 - (NSString *)monthLabel;
39 - (NSString *)yearLabel;
43 @implementation UIxCalDateLabel
46 [self->selection release];
47 [self->startDate release];
48 [self->endDate release];
54 - (void)setSelection:(NSString *)_selection {
55 ASSIGNCOPY(self->selection, _selection);
57 - (NSString *)selection {
58 return self->selection;
61 - (void)setStartDate:(NSCalendarDate *)_date {
62 ASSIGN(self->startDate, _date);
64 - (NSCalendarDate *)startDate {
65 return self->startDate;
68 - (void)setEndDate:(NSCalendarDate *)_date {
69 ASSIGN(self->endDate, _date);
71 - (NSCalendarDate *)endDate {
76 NSString *key = [self selection];
78 if([key isEqualToString:@"day"])
79 return [self dayLabel];
80 if ([key isEqualToString:@"week"])
81 return [self weekLabel];
82 if ([key isEqualToString:@"month"])
83 return [self monthLabel];
84 return [self yearLabel];
87 - (NSString *)dayLabel {
90 fmt = [self labelForKey:@"dayLabelFormat"];
91 return [self->startDate descriptionWithCalendarFormat:fmt];
94 - (NSString *)weekLabel {
97 if ([self->startDate monthOfYear] == [self->endDate monthOfYear])
98 label = [NSString stringWithFormat:@"%@ %d",
99 [self localizedNameForMonthOfYear: [self->startDate monthOfYear]],
100 [self->startDate yearOfCommonEra]];
103 le = [self localizedNameForMonthOfYear:[self->endDate monthOfYear]];
104 label = [NSString stringWithFormat:@"<nobr>%@ / %@ %d</nobr>",
106 [self->endDate yearOfCommonEra]];
112 - (NSString *)monthLabel {
116 diff = [self->startDate monthsBetweenDate:self->endDate];
118 l = [self localizedNameForMonthOfYear:[self->startDate monthOfYear]];
121 NSCalendarDate *date;
123 date = [self->startDate dateByAddingYears:0 months:0 days:15];
124 l = [self localizedNameForMonthOfYear:[date monthOfYear]];
126 return [NSString stringWithFormat:@"%@ %d",
127 l, [self->startDate yearOfCommonEra]];
130 - (NSString *)yearLabel {
131 return [NSString stringWithFormat:@"%d",
132 [self->startDate yearOfCommonEra]];
135 @end /* UIxCalDateLabel */