Exemple #1
0
        static List <DateTime> GetMissingWeatherDatesForNode(WeatherNode node, DateTime startDate, DateTime endDate)
        {
            var latitude  = node.Latitude;
            var longitude = node.Longitude;

            var dailyReports = _session.Get <WeatherDaily>(x => x.Latitude == latitude && x.Longitude == longitude).ToList();


            var missingDates        = new List <DateTime>();
            var isWesternHemisphere = node.Longitude <= 0;
            var tzOffsetMin         = isWesternHemisphere ? -2 : -14;
            var tzOffsetMax         = isWesternHemisphere ? 14 : 2;

            //Or "when is 12:00 AM at this location, relative to UTC?"

            for (DateTime date = startDate.Date; date <= endDate.Date; date = date.AddDays(1))
            {
                var timestamp       = TimeConversion.ConvertToTimestamp(date);
                var tzOffsetMinTime = TimeConversion.ConvertToTimestamp(date.AddHours(tzOffsetMin));
                var tzOffsetMaxTime = TimeConversion.ConvertToTimestamp(date.AddHours(tzOffsetMax));
                if (!dailyReports.Any(x => x.Time >= tzOffsetMinTime && x.Time <= tzOffsetMaxTime))
                {
                    var tzOffsetForDate = TimeConversion.GetTimezoneOffsetFromLocationAndDateInSeconds(timestamp, node.Latitude, node.Longitude);
                    missingDates.Add(date.AddSeconds(-tzOffsetForDate));
                }
            }
            return(missingDates);
        }
Exemple #2
0
 public void CanGetUTCDayStartFromDateTime()
 {
     //Arrange
     var now           = DateTime.Now;
     var utcDayStart   = TimeConversion.ConvertToTimestamp(DateTime.SpecifyKind(now.Date, DateTimeKind.Utc));
     var localDayStart = TimeConversion.ConvertToTimestamp(now.Date);
 }
Exemple #3
0
        public void CanStripHours()
        {
            //Arrange
            var dayStart      = TimeConversion.ConvertToTimestamp(DateTime.SpecifyKind(DateTime.Now.Date, DateTimeKind.Utc));
            var testTimestamp = dayStart + 12345;

            //Act
            var testStripHours = TimeConversion.StripHours(testTimestamp);

            //Assert
            Assert.AreEqual(dayStart, testStripHours);
        }
 public virtual IHttpActionResult GetLatest(int latitude, int longitude)
 {
     return(GetAtTime(latitude, longitude, TimeConversion.ConvertToTimestamp(DateTime.Now)));
 }