TimeZone settings and UtcOffset

Aug 24, 2007 at 11:15 PM
Edited Aug 24, 2007 at 11:17 PM
It seems silly to me for the UtcOffset to be a configuration setting when the system provides this information. Plus, the setting won't take into account daylight saving time (I hate DST).

In the frmMain.cs there are a few places where the code has things like

appointment.Start = start.AddHours(this._gMobileSync.UtcOffset);

but we can change them to use the system function (that takes into account DST!) by simply changing the lines like that to:

appointment.Start = start.AddHours(System.TimeZone.CurrentTimeZone.GetUtcOffset(start).TotalHours);


Similarly, the other timezone setting in 1.3 for Recurring events in CreateRecurrenceRule can be replaced with something like this (I couldn't find a proper list of what TZIDs are valid, if this method doesn't work, a simple lookup table could be used insetad):

timezone = Abbreviate(System.TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? System.TimeZone.CurrentTimeZone.DaylightName : System.TimeZone.CurrentTimeZone.StandardName);

----


// return all capital letters from a string
private static string Abbreviate(string str)
{
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"[a-z\s]");
return (r.Replace(str, ""));
}