From 5e84df5faa214b5eda97796ae62bd1a05ab769a7 Mon Sep 17 00:00:00 2001 From: C Robert Date: Thu, 20 Aug 2009 14:30:52 +0000 Subject: [PATCH] Mantis 1911: Calendrier - support des dates courtes Monotone-Parent: 7f0d410fd526f1879ea158593030d6d7b46be292 Monotone-Revision: a49dddbcfd99daf939a96a58365d763aadf1efc8 Monotone-Author: crobert@inverse.ca Monotone-Date: 2009-08-20T14:30:52 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 2 ++ UI/Scheduler/UIxDatePicker.h | 3 ++ UI/Scheduler/UIxDatePicker.m | 67 +++++++++++++++++++++++++++--------- 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index f87a4233e..ea7792c07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ return a 409 code when a folder with the same name exists. * SoObjects/SOGo/SOGoParentFolder.m (hasLocalSubFolderNamed): Added for Mantis 2040. + * UI/Scheduler/UIxDatePicker.m: Fix to use user-defined format, if any. + Mantis 1911. 2009-08-19 Cyril Robert diff --git a/UI/Scheduler/UIxDatePicker.h b/UI/Scheduler/UIxDatePicker.h index dcfd2cf46..b7746cf30 100644 --- a/UI/Scheduler/UIxDatePicker.h +++ b/UI/Scheduler/UIxDatePicker.h @@ -35,12 +35,15 @@ id year; NSString *label; BOOL isDisabled; + NSString *format; + NSString *jsFormat; } - (NSString *) dateID; - (NSString *) dateFormat; - (NSString *) jsDateFormat; - (BOOL) useISOFormats; +- (void) setupFormat; @end #endif /* UIXDATEPICKER_H */ diff --git a/UI/Scheduler/UIxDatePicker.m b/UI/Scheduler/UIxDatePicker.m index d74d4c1a5..bea955813 100644 --- a/UI/Scheduler/UIxDatePicker.m +++ b/UI/Scheduler/UIxDatePicker.m @@ -21,6 +21,7 @@ #import #import +#import #import #import @@ -35,6 +36,8 @@ if ((self = [super init])) { isDisabled = NO; + format = nil; + jsFormat = nil; } return self; @@ -110,31 +113,63 @@ - (NSString *) formattedDateString { - char buf[22]; + NSMutableString *buf; + NSString *_day, *_month, *_year, *_syear; - if ([self useISOFormats]) { - sprintf(buf, "%04d-%02d-%02d", - [[self year] intValue], - [[self month] intValue], - [[self day] intValue]); - } - else { - sprintf(buf, "%02d/%02d/%04d", - [[self day] intValue], - [[self month] intValue], - [[self year] intValue]); - } - return [NSString stringWithCString:buf]; + if (!format) + [self setupFormat]; + + _day = [NSString stringWithFormat: @"%02d", [[self day] intValue]]; + _month = [NSString stringWithFormat: @"%02d", [[self month] intValue]]; + _year = [NSString stringWithFormat: @"%04d", [[self year] intValue]]; + _syear = [NSString stringWithFormat: @"%02d", [[self year] intValue] % 100]; + + buf = [NSMutableString stringWithString: jsFormat]; + [buf replaceString: @"dd" withString: _day]; + [buf replaceString: @"mm" withString: _month]; + [buf replaceString: @"yyyy" withString: _year]; + [buf replaceString: @"yy" withString: _syear]; + + return buf; } - (NSString *) dateFormat { - return [self useISOFormats] ? @"%Y-%m-%d" : @"%d/%m/%Y"; + if (!format) + [self setupFormat]; + return format; } - (NSString *) jsDateFormat { - return [self useISOFormats] ? @"yyyy-mm-dd" : @"dd/mm/yyyy"; + if (!format) + [self setupFormat]; + return jsFormat; +} + +- (void) setupFormat +{ + NSUserDefaults *ud; + NSMutableString *tmp; + + ud = [[[self context] activeUser] userDefaults]; + tmp = [NSMutableString stringWithString: + [ud stringForKey: @"ShortDateFormat"]]; + if (!tmp) + { + if ([self useISOFormats]) + tmp = [NSMutableString stringWithString: @"%Y-%m-%d"]; + else + tmp = [NSMutableString stringWithString: @"%d/%m/%Y"]; + } + + format = [NSString stringWithString: tmp]; + + [tmp replaceString: @"%d" withString: @"dd"]; + [tmp replaceString: @"%m" withString: @"mm"]; + [tmp replaceString: @"%Y" withString: @"yyyy"]; + [tmp replaceString: @"%y" withString: @"yy"]; + jsFormat = [NSString stringWithString: tmp]; } /* action */