]> err.no Git - scalable-opengroupware.org/blob - Misc/ZideStore/UI-X/Scheduler/UIxCalDateLabel.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1004 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / Misc / ZideStore / UI-X / Scheduler / UIxCalDateLabel.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OGo
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23
24 #include <NGObjWeb/NGObjWeb.h>
25
26
27 @interface UIxCalDateLabel : WOComponent
28 {
29     NSString *selection;
30     NSCalendarDate *startDate;
31     NSCalendarDate *endDate;
32 }
33
34 - (NSString *)dayLabel;
35 - (NSString *)weekLabel;
36 - (NSString *)monthLabel;
37 - (NSString *)yearLabel;
38
39 @end
40
41
42 @implementation UIxCalDateLabel
43
44 - (void)dealloc {
45     [self->selection release];
46     [self->startDate release];
47     [self->endDate release];
48     [super dealloc];
49 }
50
51 - (void)setSelection:(NSString *)_selection {
52     ASSIGN(self->selection, _selection);
53 }
54
55 - (NSString *)selection {
56     return self->selection;
57 }
58
59 - (void)setStartDate:(NSCalendarDate *)_date {
60     ASSIGN(self->startDate, _date);
61 }
62
63 - (NSCalendarDate *)startDate {
64     return self->startDate;
65 }
66
67 - (void)setEndDate:(NSCalendarDate *)_date {
68     ASSIGN(self->endDate, _date);
69 }
70
71 - (NSCalendarDate *)endDate {
72     return self->endDate;
73 }
74
75 - (NSString *)label {
76     NSString *key = [self selection];
77     if([key isEqualToString:@"day"])
78         return [self dayLabel];
79     else if([key isEqualToString:@"week"])
80         return [self weekLabel];
81     else if([key isEqualToString:@"month"])
82         return [self monthLabel];
83     return [self yearLabel];
84 }
85
86 - (NSString *)dayLabel {
87     return [self->startDate descriptionWithCalendarFormat:@"%Y-%m-%d"];
88 }
89
90 - (NSString *)weekLabel {
91     NSString *label;
92     
93     label = [self->startDate descriptionWithCalendarFormat:@"%B %Y"];
94     if([self->startDate monthOfYear] != [self->endDate monthOfYear]) {
95         NSString *ext;
96         
97         ext = [self->endDate descriptionWithCalendarFormat:@"%B %Y"];
98         label = [NSString stringWithFormat:@"<nobr>%@ / %@</nobr>",
99                                             label,
100                                             ext];
101     }
102     return label;
103 }
104
105 - (NSString *)monthLabel {
106     return [self->startDate descriptionWithCalendarFormat:@"%B %Y"];
107 }
108
109 - (NSString *)yearLabel {
110     return [self->startDate descriptionWithCalendarFormat:@"%Y"];
111 }
112
113 @end