diff --git a/ChangeLog b/ChangeLog index d8b930b4f..ed0a709c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-10-04 Wolfgang Sourdeau + * UI/SOGoUI/UIxComponent.m ([UIxComponent + -_cDateFromShortDateString:dateStringandShortTimeString:timeString]): new method to compute the selected date from the "day" and "hm" query parameters (if found). This method replaces the old algorithm that was found in the "selectedDate" method. + * Main/sogod.m (main): initialize the NSTimeZone's defaultTimeZone to the value of SOGoServerTimeZone or "Canada/Eastern" if not found. diff --git a/UI/SOGoUI/UIxComponent.m b/UI/SOGoUI/UIxComponent.m index f71093c70..9e4870c69 100644 --- a/UI/SOGoUI/UIxComponent.m +++ b/UI/SOGoUI/UIxComponent.m @@ -371,43 +371,92 @@ static BOOL uixDebugEnabled = NO; } /* date */ +- (NSCalendarDate *) _cDateFromShortDateString: (NSString *) dateString + andShortTimeString: (NSString *) timeString +{ + unsigned int year, month, day, hour, minute, total; + NSCalendarDate *cDate, *tmpDate; + NSTimeZone *uTZ; + + uTZ = [[self clientObject] userTimeZone]; + + if (dateString && [dateString length] == 8) + { + total = [dateString intValue]; + year = total / 10000; + total -= year * 10000; + month = total / 100; + day = total - (month * 100); + } + else + { + tmpDate = [NSCalendarDate calendarDate]; + [tmpDate setTimeZone: uTZ]; + + year = [tmpDate yearOfCommonEra]; + month = [tmpDate monthOfYear]; + day = [tmpDate dayOfMonth]; + } + + if (timeString && [timeString length] == 4) + { + total = [timeString intValue]; + hour = total / 100; + minute = total = (hour * 100); + } + else + { + hour = 12; + minute = 0; + } + + cDate = [NSCalendarDate dateWithYear: year month: month day: day + hour: hour minute: minute second: 0 + timeZone: uTZ]; + + return cDate; +} - (NSCalendarDate *) selectedDate { - NSString *s, *dateString; - NSCalendarDate *cdate; - unsigned hour, minute; - if (!_selectedDate) { - s = [self queryParameterForKey: @"day"]; - if ([s length] > 0) - dateString = [s stringByAppendingFormat: @" %@", - [[[self clientObject] userTimeZone] abbreviation]]; - else - { - cdate = [NSCalendarDate calendarDate]; - dateString = [NSString stringWithFormat: @"%.4d%.2d%.2d %@", - [cdate yearOfCommonEra], - [cdate monthOfYear], - [cdate dayOfMonth], - [[[self clientObject] userTimeZone] abbreviation]]; - } - - cdate = [NSCalendarDate dateWithString: dateString - calendarFormat: @"%Y%m%d %Z"]; - s = [self queryParameterForKey: @"hm"]; - if ([s length] == 4) - { - hour = [[s substringToIndex: 2] unsignedIntValue]; - minute = [[s substringFromIndex: 2] unsignedIntValue]; - _selectedDate = [cdate hour: hour minute: minute]; - } - else - _selectedDate = [cdate hour: 12 minute: 0]; - + _selectedDate + = [self _cDateFromShortDateString: [self queryParameterForKey: @"day"] + andShortTimeString: [self queryParameterForKey: @"hm"]]; [_selectedDate retain]; } +// s = [self queryParameterForKey: @"day"]; + +// NSLog (@"query value 'day' = '%@'", s); +// if ([s length] > 0) +// dateString = [s stringByAppendingFormat: @" %@", +// [[[self clientObject] userTimeZone] abbreviation]]; +// else +// { +// cdate = [NSCalendarDate calendarDate]; +// dateString = [NSString stringWithFormat: @"%.4d%.2d%.2d %@", +// [cdate yearOfCommonEra], +// [cdate monthOfYear], +// [cdate dayOfMonth], +// [[[self clientObject] userTimeZone] abbreviation]]; +// } + +// cdate = [NSCalendarDate dateWithString: dateString +// calendarFormat: @"%Y%m%d %Z"]; +// s = [self queryParameterForKey: @"hm"]; +// NSLog (@"query value 'hm' = '%@'", s); +// if ([s length] == 4) +// { +// hour = [[s substringToIndex: 2] unsignedIntValue]; +// minute = [[s substringFromIndex: 2] unsignedIntValue]; +// _selectedDate = [cdate hour: hour minute: minute]; +// } +// else +// _selectedDate = [cdate hour: 12 minute: 0]; + +// [_selectedDate retain]; +// } return _selectedDate; }