2 Copyright (C) 2004-2005 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 <NGObjWeb/WOComponent.h>
26 @interface UIxDatePicker : WOComponent
37 - (NSString *)dateFormat;
38 - (NSString *)jsDateFormat;
39 - (BOOL)useISOFormats;
44 @implementation UIxDatePicker
48 if ((self = [super init]))
57 [self->dateID release];
59 [self->month release];
61 [self->label release];
67 - (void)setDateID:(NSString *)_dateID {
68 ASSIGNCOPY(self->dateID, _dateID);
70 - (NSString *)dateID {
74 - (void)setDay:(id)_day {
75 ASSIGN(self->day, _day);
80 - (void)setMonth:(id)_month {
81 ASSIGN(self->month, _month);
86 - (void)setYear:(id)_year {
87 ASSIGN(self->year, _year);
94 - (void)setLabel:(NSString *)_label {
95 ASSIGNCOPY(self->label, _label);
104 - (BOOL)useISOFormats {
106 NSNumber *useISOFormats;
108 ctx = [self context];
109 useISOFormats = [ctx valueForKey:@"useISOFormats"];
110 if (!useISOFormats) {
111 NSArray *languages = [ctx resourceLookupLanguages];
112 if (languages && [languages count] > 0) {
113 if ([[languages objectAtIndex:0] isEqualToString:@"French"]) {
114 useISOFormats = [NSNumber numberWithBool:NO];
118 useISOFormats = [NSNumber numberWithBool:YES];
119 [ctx takeValue:useISOFormats forKey:@"useISOFormats"];
121 return [useISOFormats boolValue];
124 - (NSString *) formattedDateString
128 if ([self useISOFormats]) {
129 sprintf(buf, "%04d-%02d-%02d",
130 [[self year] intValue],
131 [[self month] intValue],
132 [[self day] intValue]);
135 sprintf(buf, "%02d/%02d/%04d",
136 [[self day] intValue],
137 [[self month] intValue],
138 [[self year] intValue]);
140 return [NSString stringWithCString:buf];
143 - (NSString *) dateFormat
145 return [self useISOFormats] ? @"%Y-%m-%d" : @"%d/%m/%Y";
148 - (NSString *) jsDateFormat
150 return [self useISOFormats] ? @"yyyy-mm-dd" : @"dd/mm/yyyy";
155 - (void) takeValuesFromRequest: (WORequest *) _rq
156 inContext: (WOContext *)_ctx
158 NSString *dateString;
161 dateString = [_rq formValueForKey:[self dateID]];
162 if (dateString == nil) {
163 [self debugWithFormat:@"got no date string!"];
167 d = [NSCalendarDate dateWithString:dateString
168 calendarFormat:[self dateFormat]];
170 [self warnWithFormat:@"Could not parse dateString: '%@'",
174 [self setDay: [NSNumber numberWithInt:[d dayOfMonth]]];
175 [self setMonth:[NSNumber numberWithInt:[d monthOfYear]]];
176 [self setYear: [NSNumber numberWithInt:[d yearOfCommonEra]]];
178 [super takeValuesFromRequest:_rq inContext:_ctx];
181 - (void) setDisabled: (BOOL) disabled
183 isDisabled = disabled;
191 @end /* UIxDatePicker */