diff --git a/ChangeLog b/ChangeLog index b64179ab7..3d05fc45e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,11 @@ of the new method [iCalTimeZone knownTimeZoneNames] instead of [NSTimeZone knownTimeZoneNames] to avoid listing tons of useless timezones. + * UI/PreferencesUI/UIxPreferences.m (-userTimeZone): since we now + offer a limited number of timezones, the user timezone could be + unrecognized. In this case, try to find a timezone with the same + GMT offset. + 2011-03-22 Wolfgang Sourdeau * OpenChange/MAPIStoreCalendarMessage.m (-init): new method to diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 685c44785..8b47046a5 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -1,8 +1,9 @@ /* UIxPreferences.m - this file is part of SOGo * - * Copyright (C) 2007-2010 Inverse inc. + * Copyright (C) 2007-2011 Inverse inc. * * Author: Wolfgang Sourdeau + * Francis Lachapelle * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +34,7 @@ #import #import +#import #import #import @@ -156,7 +158,47 @@ - (NSString *) userTimeZone { - return [userDefaults timeZoneName]; + NSString *name; + iCalTimeZone *tz; + + name = [userDefaults timeZoneName]; + tz = [iCalTimeZone timeZoneForName: name]; + + if (!tz) + { + // The specified timezone is not in our Olson database. + // Look for a known timezone with the same GMT offset. + NSString *current; + NSCalendarDate *now; + NSEnumerator *zones; + BOOL found; + unsigned int offset; + + found = NO; + now = [NSCalendarDate calendarDate]; + offset = [[userDefaults timeZone] secondsFromGMTForDate: now]; + zones = [[iCalTimeZone knownTimeZoneNames] objectEnumerator]; + + while ((current = [zones nextObject])) + { + tz = [iCalTimeZone timeZoneForName: current]; + if ([[tz periodForDate: now] secondsOffsetFromGMT] == offset) + { + found = YES; + break; + } + } + + if (found) + { + [self warnWithFormat: @"User %@ has an unknown timezone (%@) -- replaced by %@", [user login], name, current]; + name = current; + } + else + [self errorWithFormat: @"User %@ has an unknown timezone (%@)", [user login], name]; + } + + return name; } - (void) setUserTimeZone: (NSString *) newUserTimeZone