ConvertDateTimeToUniversalDateTime method

DateTime ConvertDateTimeToUniversalDateTime(
  1. DateTime value
)
Converts a DateTime to UTC the way C# handles the DateTime kinds: a UTC DateTime is returned as is, a [datetime.TZDateTime] (Local kind) is converted from its own time zone and a plain local DateTime (Unspecified kind) is read as a wall-clock time in the service's time zone, or in the platform's local time zone when [TimeZone] is null (C#'s default, TimeZoneInfo.Local). The value.

Implementation

DateTime ConvertDateTimeToUniversalDateTime(DateTime value) {
  if (value.isUtc) {
    return value is datetime.TZDateTime
        ? DateTime.fromMicrosecondsSinceEpoch(
            value.microsecondsSinceEpoch,
            isUtc: true,
          )
        : value;
  } else if (value is datetime.TZDateTime || TimeZone == null) {
    return DateTime.fromMicrosecondsSinceEpoch(
      value.microsecondsSinceEpoch,
      isUtc: true,
    );
  } else {
    return EwsUtilities.ConvertTime(
      value,
      EwsUtilities.LocationFromTimeZone(TimeZone!),
      datetime.UTC,
    );
  }
}