I have since found out that the problem is the EWS XML format. As can be seen here, it does not contain the full time zone information (e.g. name), only a subset:
<TimeZone>
<Bias>480</Bias>
<StandardTime>
<Bias>0</Bias>
<Time>02:00:00</Time>
<DayOrder>5</DayOrder>
<Month>10</Month>
<DayOfWeek>Sunday</DayOfWeek>
</StandardTime>
<DaylightTime>
<Bias>-60</Bias>
<Time>02:00:00</Time>
<DayOrder>1</DayOrder>
<Month>4</Month>
<DayOfWeek>Sunday</DayOfWeek>
</DaylightTime>
</TimeZone>
This subset is then parsed back into a time zone in this EWS Managed API code, with this really useful Guid "Id" (the Id is different every time I call GetUserAvailability
, although the timezone is still the same):
return TimeZoneInfo.CreateCustomTimeZone(
Guid.NewGuid().ToString(),
-this.bias,
"Custom time zone",
"Standard time",
"Daylight time",
new TimeZoneInfo.AdjustmentRule[] { adjustmentRule });
So I guess I can expect that in 99% of the cases I will find one or more matching time zones in the list of available system time zones, and I am for now using the extension method:
public static TimeZoneInfo ToSystemTimeZone(this TimeZoneInfo customTimeZone)
{
var tz = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(x => x.HasSameRules(customTimeZone));
if (tz != null) return tz;
else return customTimeZone;
}
This provides the first system time zone that has the same rules as the custom time zone. It's not a 100% match, since there may be multiple time zones with the same rules, but at least this should keep all the time zone information that is exposed via EWS.