Esempio n. 1
0
        public async void TimeMachineUnitsCanBeSpecified()
        {
            var client = new ForecastApi(this.apiKey);
            var date   = DateTime.Now.Subtract(new TimeSpan(2, 0, 0, 0));

            var result = await client.GetTimeMachineWeatherAsync(AlcatrazLatitude, AlcatrazLongitude, date, Unit.CA);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Flags.Units, Is.EqualTo(Unit.CA.ToValue()));
        }
Esempio n. 2
0
        public async void CanRetrieveForThePast()
        {
            var client = new ForecastApi(this.apiKey);
            var date   = DateTime.Now.Subtract(new TimeSpan(2, 0, 0, 0));

            var result = await client.GetTimeMachineWeatherAsync(AlcatrazLatitude, AlcatrazLongitude, date);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Currently, Is.Not.Null);
        }
Esempio n. 3
0
        public async void TimeMachineWorksWithPeriodDecimalSeperator()
        {
            var client = new ForecastApi(this.apiKey);
            var date   = DateTime.Now.Subtract(new TimeSpan(2, 0, 0, 0));

            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            var result = await client.GetTimeMachineWeatherAsync(AlcatrazLatitude, AlcatrazLongitude, date, Unit.CA);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Currently, Is.Not.Null);
        }
Esempio n. 4
0
        public async void TimeMachineExclusionWorksCorrectly()
        {
            var client        = new ForecastApi(this.apiKey);
            var date          = DateTime.Now.Subtract(new TimeSpan(2, 0, 0, 0));
            var exclusionList = new List <Exclude> {
                Exclude.Hourly
            };

            var result = await client.GetTimeMachineWeatherAsync(AlcatrazLatitude, AlcatrazLongitude, date, Unit.US, exclusionList);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Currently, Is.Not.Null);
            Assert.That(result.Hourly, Is.Null);
        }
Esempio n. 5
0
        public static List <ForecastHourly> GetHourlyWeatherOverPeriod(SimpleTime start, SimpleTime end, double lat, double lng)
        {
            LocalDateTime begin  = new LocalDateTime(start.Year, start.Month, start.Day, 0, 0);
            LocalDateTime stop   = new LocalDateTime(end.Year, end.Month, end.Day, 0, 0);
            Period        period = Period.Between(begin, stop, PeriodUnits.Days);

            List <ForecastHourly> hourlyData = new List <ForecastHourly>();

            for (int i = 0; i <= period.Days; i++)
            {
                LocalDateTime localtime = begin.PlusDays(i);

                string       timezone = "America/Toronto";
                DateTimeZone tz       = DateTimeZoneProviders.Tzdb[timezone];

                ZonedDateTime zt        = tz.AtLeniently(localtime);
                var           tz_offset = zt.ToDateTimeOffset();

                Task.Run(async() =>
                {
                    var client      = new ForecastApi(API_KEY);
                    Forecast result = await client.GetTimeMachineWeatherAsync(lat, lng, tz_offset);
                    var hourly      = result.Hourly.Hours;
                    for (int h = 0; h < hourly.Count(); h++)
                    {
                        ForecastHourly store_hourly      = new ForecastHourly();
                        store_hourly.ApparentTemperature = hourly[h].ApparentTemperature;
                        store_hourly.CloudCover          = hourly[h].CloudCover;
                        store_hourly.DewPoint            = hourly[h].DewPoint;
                        store_hourly.Humidity            = hourly[h].Humidity;
                        store_hourly.Icon  = hourly[h].Icon;
                        store_hourly.Ozone = hourly[h].Ozone;
                        store_hourly.PrecipitationIntensity   = hourly[h].PrecipitationIntensity;
                        store_hourly.PrecipitationProbability = hourly[h].PrecipitationProbability;
                        store_hourly.Pressure    = hourly[h].Pressure;
                        store_hourly.Summary     = hourly[h].Summary;
                        store_hourly.Temperature = hourly[h].Temperature;
                        store_hourly.Time        = hourly[h].Time;
                        //Instant instant = Instant.FromDateTimeUtc(hourly[h].Time.UtcDateTime); //don't need this, already defined above
                        store_hourly.LocalTime   = zt.LocalDateTime;
                        store_hourly.Visibility  = hourly[h].Visibility;
                        store_hourly.WindBearing = hourly[h].WindBearing;
                        store_hourly.WindSpeed   = hourly[h].WindSpeed;
                        hourlyData.Add(store_hourly);
                    }
                }).Wait();
            }
            return(hourlyData);
        }
Esempio n. 6
0
 public async Task <IList <DayForecast> > GetForecast(double latitude, double longitude, DateTimeOffset?forecastDate = null)
 {
     try
     {
         var      client = new ForecastApi(FORECAST_API_KEY);
         Forecast result;
         if (forecastDate != null)
         {
             result = await client.GetTimeMachineWeatherAsync(latitude, longitude, (DateTimeOffset)forecastDate);
         }
         else
         {
             result = await client.GetWeatherDataAsync(latitude, longitude);
         }
         var days = WeatherFactory.CreateDayForecasts(result);
         return(days);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
         return(null);
     }
 }