Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
 public DateTimeOffset TimeAtLocation(Location location)
 {
     return TimeZoneInfo.ConvertTime((DateTimeOffset)DateTimeInUTC, location.TimeZoneInfo);
 }