public DateTimeAndZone GetUtcTimeZone(DateTime local, string state, string country) { var timeZone = GetTimeZoneInfo(state, country); if (timeZone == null) { return(null); } return(DateTimeAndZone.FromLocal(local, timeZone)); }
public static DateTimeAndZone FromLocal(DateTime local, TimeZoneInfo timeZone) { if (local.Kind == DateTimeKind.Utc) { throw new ArgumentException("DateTime utc must be .Kind == DateTimeKind.Unspecified, not Utc.", "local"); } // We need to push this date from Local (default for Parse) to Unspecified because it's outside // the limited timezone space the DateTime structure understands (Local, UTC, and go fish) if (local.Kind == DateTimeKind.Local) { local = DateTime.SpecifyKind(local, DateTimeKind.Unspecified); } var u = new DateTimeAndZone(TimeZoneInfo.ConvertTimeToUtc(local, timeZone), timeZone); return(u); }
public static DateTimeAndZone FromLocal(DateTime local, TimeZoneInfo timeZone) { if (local.Kind == DateTimeKind.Utc) throw new ArgumentException("DateTime utc must be .Kind == DateTimeKind.Unspecified, not Utc.", "local"); // We need to push this date from Local (default for Parse) to Unspecified because it's outside // the limited timezone space the DateTime structure understands (Local, UTC, and go fish) if (local.Kind == DateTimeKind.Local) local = DateTime.SpecifyKind(local, DateTimeKind.Unspecified); var u = new DateTimeAndZone(TimeZoneInfo.ConvertTimeToUtc(local, timeZone), timeZone); return u; }
public DateTimeAndZone GetUtcTimeZone(DateTime local, string state, string country, TimeZoneId defaultTimeZoneId) { var timeZone = GetTimeZoneInfo(state, country, defaultTimeZoneId); return(DateTimeAndZone.FromLocal(local, timeZone)); }