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 #import <Foundation/NSValue.h>
23 #import <Foundation/NSCalendarDate.h>
25 #import <NGObjWeb/WOComponent.h>
26 #import <NGObjWeb/WOContext.h>
27 #import <NGObjWeb/WORequest.h>
28 #import <NGExtensions/NSObject+Logs.h>
32 @interface UIxDatePicker : WOComponent
42 - (NSString *) dateID;
43 - (NSString *) dateFormat;
44 - (NSString *) jsDateFormat;
45 - (BOOL) useISOFormats;
48 @implementation UIxDatePicker
52 if ((self = [super init]))
61 [self->dateID release];
63 [self->month release];
65 [self->label release];
71 - (void)setDateID:(NSString *)_dateID {
72 ASSIGNCOPY(self->dateID, _dateID);
74 - (NSString *)dateID {
78 - (void)setDay:(id)_day {
79 ASSIGN(self->day, _day);
84 - (void)setMonth:(id)_month {
85 ASSIGN(self->month, _month);
90 - (void)setYear:(id)_year {
91 ASSIGN(self->year, _year);
98 - (void)setLabel:(NSString *)_label {
99 ASSIGNCOPY(self->label, _label);
101 - (NSString *)label {
108 - (BOOL)useISOFormats {
110 NSNumber *useISOFormats;
112 ctx = [self context];
113 useISOFormats = [ctx valueForKey:@"useISOFormats"];
114 if (!useISOFormats) {
115 NSArray *languages = [ctx resourceLookupLanguages];
116 if (languages && [languages count] > 0) {
117 if ([[languages objectAtIndex:0] isEqualToString:@"French"]) {
118 useISOFormats = [NSNumber numberWithBool:NO];
122 useISOFormats = [NSNumber numberWithBool:YES];
123 [ctx takeValue:useISOFormats forKey:@"useISOFormats"];
125 return [useISOFormats boolValue];
128 - (NSString *) formattedDateString
132 if ([self useISOFormats]) {
133 sprintf(buf, "%04d-%02d-%02d",
134 [[self year] intValue],
135 [[self month] intValue],
136 [[self day] intValue]);
139 sprintf(buf, "%02d/%02d/%04d",
140 [[self day] intValue],
141 [[self month] intValue],
142 [[self year] intValue]);
144 return [NSString stringWithCString:buf];
147 - (NSString *) dateFormat
149 return [self useISOFormats] ? @"%Y-%m-%d" : @"%d/%m/%Y";
152 - (NSString *) jsDateFormat
154 return [self useISOFormats] ? @"yyyy-mm-dd" : @"dd/mm/yyyy";
159 - (void) takeValuesFromRequest: (WORequest *) _rq
160 inContext: (WOContext *)_ctx
162 NSString *dateString;
165 dateString = [_rq formValueForKey:[self dateID]];
166 if (dateString == nil) {
167 [self debugWithFormat:@"got no date string!"];
171 d = [NSCalendarDate dateWithString:dateString
172 calendarFormat:[self dateFormat]];
174 [self warnWithFormat:@"Could not parse dateString: '%@'",
178 [self setDay: [NSNumber numberWithInt:[d dayOfMonth]]];
179 [self setMonth:[NSNumber numberWithInt:[d monthOfYear]]];
180 [self setYear: [NSNumber numberWithInt:[d yearOfCommonEra]]];
182 [super takeValuesFromRequest:_rq inContext:_ctx];
185 - (void) setDisabled: (BOOL) disabled
187 isDisabled = disabled;
195 @end /* UIxDatePicker */