public static LocationDateTime AtLocation(DateTime locationDateTime, Location location) { if (locationDateTime.Kind != DateTimeKind.Unspecified) throw new ArgumentException("DateTimeKind should be unspecified"); var utcTime = TimeZoneInfo.ConvertTimeToUtc(locationDateTime, location.TimeZoneInfo); return new LocationDateTime(location, utcTime); }
public static LocationDateTime ToLocationDateTime(this DateTime dateTime, Location location) { if (dateTime == null) return null; if (location == null) throw new ArgumentNullException(nameof(location)); return LocationDateTime.AtLocation(dateTime, location); }
public LocationDateTime(Location location, DateTime dateTimeUTC) { if (location == null) throw new ArgumentNullException(nameof(location)); if (dateTimeUTC == null) throw new ArgumentNullException(nameof(dateTimeUTC)); if (dateTimeUTC.Kind != DateTimeKind.Utc) throw new ArgumentException("Date Time not in UTC"); Location = location; DateTimeInUTC = dateTimeUTC; DateTimeInLocation = TimeAtLocation(Location); }
public DateTimeOffset TimeAtLocation(Location location) { return TimeZoneInfo.ConvertTime((DateTimeOffset)DateTimeInUTC, location.TimeZoneInfo); }