public void ShouldConvertTimeSpanToShortDateString()
        {
            var time = new TimeSpan(15, 10, 30);

            var converter = new TimeSpanConverter();

            var result = converter.Convert(time, null, null, null);

            Assert.AreEqual("15:10", result);

            time = new TimeSpan(1, 3, 15);

            result = converter.Convert(time, null, null, null);

            Assert.AreEqual("01:03", result);
        }
        public void ShouldConvertNullValue()
        {
            var converter = new TimeSpanConverter();

            var result = converter.Convert(null, null, null, null);

            Assert.IsNull(result);
        }
        public void HandleNull()
        {
            var converter = new TimeSpanConverter();

            var result = converter.Convert(null);

            Assert.Null(result);
        }
Exemplo n.º 4
0
    public void TestTimeSpanConverter()
    {
        var msecSpec = "15msec";
        var secSpec  = "12 seconds";
        var minSpec  = "3m";
        var hourSpec = "2 h";
        var daySpec  = "3 day";
        var weekSpec = "1w";
        var yearSpec = "2 years";

        ITimeSpanConverter converter = new TimeSpanConverter();

        var msec = converter.Convert(msecSpec);
        var sec  = converter.Convert(secSpec);
        var min  = converter.Convert(minSpec);
        var hour = converter.Convert(hourSpec);
        var day  = converter.Convert(daySpec);
        var week = converter.Convert(weekSpec);
        var year = converter.Convert(yearSpec);

        Assert.AreEqual(TimeSpan.FromMilliseconds(15), msec);
        Assert.AreEqual(TimeSpan.FromSeconds(12), sec);
        Assert.AreEqual(TimeSpan.FromMinutes(3), min);
        Assert.AreEqual(TimeSpan.FromHours(2), hour);
        Assert.AreEqual(TimeSpan.FromDays(3), day);
        Assert.AreEqual(TimeSpan.FromDays(1 * 7), week);
        Assert.AreEqual(TimeSpan.FromDays(2 * 365), year);
    }
        public void HandleNullableTimeSpansWithNoValue()
        {
            TimeSpan?input = null;

            var converter = new TimeSpanConverter();

            var result = converter.Convert(input);

            Assert.Null(result);
        }
        public void HandleTimeSpans()
        {
            TimeSpan input = new TimeSpan(12220);

            var converter = new TimeSpanConverter();

            var result = converter.Convert(input);

            Assert.Equal(1.22, result);
        }
        protected override void PostTestInit(object sender, PluginEventArgs e)
        {
            RetryFailedRequestsInfo retryFailedRequestsInfo = GetRetryFailedRequestsInfo(e.TestMethodMemberInfo);

            if (retryFailedRequestsInfo != null)
            {
                var client = e.Container.Resolve <ApiClientService>();
                client.PauseBetweenFailures = TimeSpanConverter.Convert(retryFailedRequestsInfo.PauseBetweenFailures, retryFailedRequestsInfo.TimeUnit);
                client.MaxRetryAttempts     = retryFailedRequestsInfo.MaxRetryAttempts;
            }
        }
        protected override void PostBeforeScenario(object sender, TestWorkflowPluginEventArgs e)
        {
            var retryFailedRequestsInfo = new RetryFailedRequestsInfo()
            {
                MaxRetryAttempts     = _maxRetryAttempts,
                PauseBetweenFailures = _pauseBetweenFailures,
                TimeUnit             = _timeUnit,
            };

            var client = ServicesCollection.Current.Resolve <ApiClientService>();

            client.PauseBetweenFailures = TimeSpanConverter.Convert(retryFailedRequestsInfo.PauseBetweenFailures, retryFailedRequestsInfo.TimeUnit);
            client.MaxRetryAttempts     = retryFailedRequestsInfo.MaxRetryAttempts;
        }
        public void Conversion()
        {
            // Arrange
            IConverter converter     = new TimeSpanConverter();
            var        value         = "3:15:14";
            var        expectedValue = new TimeSpan(3, 15, 14);

            // Act
            var actualValue = converter.Convert(value, converter.TargetType);

            // Assert
            Assert.NotNull(actualValue);
            Assert.IsType <TimeSpan>(actualValue);
            Assert.Equal(expectedValue, (TimeSpan)actualValue);
        }
Exemplo n.º 10
0
        private void sld_Holding(object sender, HoldingRoutedEventArgs e)
        {
            double value = sld.Value;

            sld.Minimum = value - zoomWidth * value;
            sld.Maximum = value + (1 - value) * zoomWidth;

            double   min       = sld.Minimum;
            double   max       = sld.Maximum;
            TimeSpan duration  = Duration;
            TimeSpan beginTime = duration.Multiply(min);
            TimeSpan endTime   = duration.Multiply(max);

            tblBegin.Text       = TimeSpanConverter.Convert(beginTime);
            tblEnd.Text         = TimeSpanConverter.Convert(endTime);
            tblBegin.Visibility = tblEnd.Visibility = Visibility.Visible;
        }
Exemplo n.º 11
0
        public ApiClientService GetApiClientService(string url = null, bool sharedCookies = true, int maxRetryAttempts = 1, int pauseBetweenFailures = 1, TimeUnit timeUnit = TimeUnit.Seconds)
        {
            if (!ShouldReuseRestClient)
            {
                ServicesCollection.Current.UnregisterSingleInstance <ApiClientService>();
            }

            bool isClientRegistered = ServicesCollection.Current.IsRegistered <ApiClientService>();
            var  client             = ServicesCollection.Current.Resolve <ApiClientService>();

            if (!isClientRegistered || client == null)
            {
                client = new ApiClientService();
                if (string.IsNullOrEmpty(url))
                {
                    var apiSettingsConfig = ConfigurationService.GetSection <ApiSettings>();
                    if (apiSettingsConfig == null)
                    {
                        throw new SettingsNotFoundException("apiSettings");
                    }

                    client.WrappedClient.BaseUrl = new Uri(apiSettingsConfig.BaseUrl);
                }
                else
                {
                    client.WrappedClient.BaseUrl = new Uri(url);
                }

                if (sharedCookies)
                {
                    client.WrappedClient.CookieContainer = new System.Net.CookieContainer();
                }

                client.PauseBetweenFailures = TimeSpanConverter.Convert(pauseBetweenFailures, timeUnit);
                client.MaxRetryAttempts     = maxRetryAttempts;

                ServicesCollection.Current.RegisterInstance(client);
            }

            return(client);
        }
Exemplo n.º 12
0
        public void TimeSpanConverterTest()
        {
            var converter = new TimeSpanConverter();

            TimeSpan?t1 = new TimeSpan(0, 0, 0, 30, 126);

            Assert.AreEqual("30,12", converter.Convert(t1, null, null, null));
            Assert.AreEqual("0:30,12", converter.Convert(t1, null, "m", null));
            Assert.AreEqual("00:30,12", converter.Convert(t1, null, "mm", null));

            TimeSpan?t2 = new TimeSpan(0, 0, 1, 30, 126);

            Assert.AreEqual("1:30,12", converter.Convert(t2, null, null, null));
            Assert.AreEqual("01:30,12", converter.Convert(t2, null, "mm", null));

            TimeSpan?t3 = new TimeSpan(0, 1, 1, 30, 126);

            Assert.AreEqual("01:01:30,12", converter.Convert(t3, null, null, null));
        }
Exemplo n.º 13
0
 public void TestConvert1()
 {
     _converter.Convert(TimeSpan.Zero, typeof(string), null, CultureInfo.CurrentUICulture).Should().Be("0 milliseconds");
     _converter.Convert(TimeSpan.FromMilliseconds(1), typeof(string), null, CultureInfo.CurrentUICulture).Should().Be("1 millisecond");
     _converter.Convert(TimeSpan.FromMilliseconds(2), typeof(string), null, CultureInfo.CurrentUICulture).Should().Be("2 milliseconds");
     _converter.Convert(TimeSpan.FromMilliseconds(999), typeof(string), null, CultureInfo.CurrentUICulture).Should().Be("999 milliseconds");
 }
        public void BadValueConversion()
        {
            // Arrange
            IConverter converter = new TimeSpanConverter();
            var        value     = "Hello";
            var        expectedExceptionMessage      = Constants.ExceptionMessages.FormatConverterUnableConvert(value, typeof(TimeSpan));
            var        expectedInnerExceptionMessage = "String was not recognized as a valid TimeSpan.";

            // Act
            using (new LangageSwitcher("en-us"))
            {
                var actualException = Assert.Throws <CommandLineParserException>(() => converter.Convert(value, converter.TargetType));

                // Assert
                Assert.Equal(expectedExceptionMessage, actualException.Message);
                Assert.NotNull(actualException.InnerException);
                var actualInnerExecption = Assert.IsAssignableFrom <FormatException>(actualException.InnerException);
                Assert.Equal(expectedInnerExceptionMessage, actualInnerExecption.Message);
            }
        }
Exemplo n.º 15
0
 public void TestSetOneIgnoredUnit()
 {
     _converter.IgnoredUnits = new[] { Unit.Millisecond };
     _converter.Convert(TimeSpan.FromMilliseconds(10), typeof(string), null, CultureInfo.CurrentUICulture)
     .Should().Be("1 second");
 }
Exemplo n.º 16
0
        private async Task InitialViewModel()
        {
            CurrentTime = DateTime.Now;
            UpdateTime  = fetchresult.Location.UpdateTime;
            utcOffset   = UpdateTime - fetchresult.Location.UtcTime;
            RefreshCurrentTime();
            CurrentTimeRefreshTask();
            todayIndex = Array.FindIndex(fetchresult.DailyForecast, x =>
            {
                return(x.Date.Date == CurrentTime.Date);
            });
            nowHourIndex = Array.FindIndex(fetchresult.HourlyForecast, x =>
            {
                return((x.DateTime - CurrentTime).TotalSeconds > 0);
            });
            if (CurrentTime.Hour <= sunRise.Hours)
            {
                todayIndex--;
            }
            if (todayIndex < 0)
            {
                todayIndex = 0;
            }
            if (nowHourIndex < 0)
            {
                nowHourIndex = 0;
            }
            if (fetchresult.DailyForecast[todayIndex].SunRise == default(TimeSpan) || fetchresult.DailyForecast[todayIndex].SunSet == default(TimeSpan))
            {
                sunRise = Core.LunarCalendar.SunRiseSet.GetRise(new Models.Location(currentCityModel.Latitude, currentCityModel.Longitude), CurrentTime);
                sunSet  = Core.LunarCalendar.SunRiseSet.GetSet(new Models.Location(currentCityModel.Latitude, currentCityModel.Longitude), CurrentTime);
            }
            else
            {
                sunRise = fetchresult.DailyForecast[todayIndex].SunRise;
                sunSet  = fetchresult.DailyForecast[todayIndex].SunSet;
            }
            City        = currentCityModel.City;
            isNight     = WeatherModel.CalculateIsNight(CurrentTime, sunRise, sunSet);
            this.Glance = Models.Glance.GenerateGlanceDescription(fetchresult, isNight, TemperatureDecoratorConverter.Parameter, DateTime.Now);
            CityGlance  = (City + "  " + Glance);
            Date        = CurrentTime.ToString(settings.Preferences.GetDateFormat());

            var calendar = new CalendarInfo(CurrentTime);
            var loader   = new ResourceLoader();


            LunarCalendar = settings.Preferences.UseLunarCalendarPrimary ? (("农历 " + calendar.LunarYearSexagenary + "年" + calendar.LunarMonthText + "月" + calendar.LunarDayText + "    " + calendar.SolarTermStr).Trim()) : string.Empty;
            Hum           = ": " + fetchresult.HourlyForecast[nowHourIndex].Humidity + "%";
            Pop           = ": " + fetchresult.HourlyForecast[nowHourIndex].Pop + "%";
            Pcpn          = ": " + fetchresult.NowWeather.Precipitation + " mm";
            var v = new VisibilityConverter();

            Vis = ": " + (fetchresult.NowWeather.Visibility == null ? "N/A" : v.Convert(fetchresult.NowWeather.Visibility, null, null, null));
            var w = new WindSpeedConverter();

            Scale = ": " + (fetchresult.NowWeather.Wind == null ? "N/A" : w.Convert(fetchresult.NowWeather.Wind, null, null, null));
            var d = new WindDirectionConverter();

            Dir = ": " + (fetchresult.NowWeather.Wind == null ? "N/A" : d.Convert(fetchresult.NowWeather.Wind, null, null, null));
            var p = new PressureConverter();

            Pressure = ": " + (fetchresult.NowWeather.Pressure == null ? "N/A" : p.Convert(fetchresult.NowWeather.Pressure, null, null, null));

            var t = new TimeSpanConverter();

            SunRise       = ": " + (string)t.Convert(sunRise, null, null, null);
            SunSet        = ": " + (string)t.Convert(sunSet, null, null, null);
            this.Location = ": " + new Models.Location(currentCityModel.Latitude, currentCityModel.Longitude).ToString();
            var off = utcOffset.Hours;

            Offset = ": UTC" + (off >= 0 ? " +" : " -") + t.Convert(utcOffset, null, null, null);

            var uri = await settings.Immersive.GetCurrentBackgroundAsync(fetchresult.NowWeather.Now.Condition, isNight);

            if (uri != null)
            {
                try
                {
                    CurrentBG = new BitmapImage(uri);
                }
                catch (Exception)
                {
                }
            }
            List <KeyValuePair <int, double> > doubles0 = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > doubles1 = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > doubles2 = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > doubles3 = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > doubles5 = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > doubles4 = new List <KeyValuePair <int, double> >();

            if (!fetchresult.HourlyForecast.IsNullorEmpty())
            {
                for (int i = nowHourIndex + 1; i < fetchresult.HourlyForecast.Length; i++)
                {
                    if (fetchresult.HourlyForecast[i].Temprature != null)
                    {
                        doubles0.Add(new KeyValuePair <int, double>(i, fetchresult.HourlyForecast[i].Temprature.ActualDouble(TemperatureDecoratorConverter.Parameter)));
                    }
                    if (fetchresult.HourlyForecast[i].Pop != default(uint))
                    {
                        doubles1.Add(new KeyValuePair <int, double>(i, fetchresult.HourlyForecast[i].Pop));
                    }
                    if (fetchresult.HourlyForecast[i].Wind != null)
                    {
                        doubles4.Add(new KeyValuePair <int, double>(i, fetchresult.HourlyForecast[i].Wind.Speed.ActualDouble(WindSpeedConverter.SpeedParameter)));
                    }
                }
                var sb = new StringBuilder();
                if (doubles0 != null && doubles0.Count > 1)
                {
                    GetHourlyXText(doubles0, sb);
                    Forecasts.Add(new GraphViewModel(doubles0, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Palette.Cyan), string.Format(loader.GetString("HourlyDetailsTemperature"), doubles0.Count), Temperature.GetFormat(TemperatureDecoratorConverter.Parameter), -280, 9999, sb.ToString()));
                }
                if (doubles1 != null && doubles1.Count > 1)
                {
                    GetHourlyXText(doubles1, sb);
                    Forecasts.Add(new GraphViewModel(doubles1, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("HourlyDetailsPop"), doubles1.Count), "%", 0, 100, sb.ToString()));
                }
                if (doubles4 != null && doubles4.Count > 1)
                {
                    GetHourlyXText(doubles4, sb);
                    Forecasts.Add(new GraphViewModel(doubles4, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("HourlyDetailsWind"), doubles4.Count), Wind.GetSpeedFormat(WindSpeedConverter.SpeedParameter), 0, 1000, sb.ToString()));
                }
            }

            doubles0.Clear();
            doubles1.Clear();
            doubles2.Clear();
            doubles3.Clear();
            doubles4.Clear();
            doubles5.Clear();

            if (!fetchresult.DailyForecast.IsNullorEmpty())
            {
                for (int i = todayIndex + 1; i < fetchresult.DailyForecast.Length; i++)
                {
                    if (fetchresult.DailyForecast[i].HighTemp != null && fetchresult.DailyForecast[i].LowTemp != null)
                    {
                        doubles0.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].HighTemp.ActualDouble(TemperatureDecoratorConverter.Parameter)));
                        doubles1.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].LowTemp.ActualDouble(TemperatureDecoratorConverter.Parameter)));
                    }
                    if (fetchresult.DailyForecast[i].Pop != default(uint))
                    {
                        doubles2.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].Pop));
                    }
                    if (fetchresult.DailyForecast[i].Precipitation != default(float))
                    {
                        doubles3.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].Precipitation));
                    }
                    if (fetchresult.DailyForecast[i].Visibility != null)
                    {
                        doubles5.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].Visibility.ActualDouble(VisibilityConverter.LengthParameter)));
                    }
                    if (fetchresult.DailyForecast[i].Wind != null)
                    {
                        doubles4.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].Wind.Speed.ActualDouble(WindSpeedConverter.SpeedParameter)));
                    }
                }
                var sb = new StringBuilder();
                if (!doubles0.IsNullorEmpty() && !doubles1.IsNullorEmpty())
                {
                    GetDailyXText(doubles0, sb);
                    Forecasts.Add(new GraphViewModel(doubles0, doubles1, new SolidColorBrush(Palette.Orange), new SolidColorBrush(Palette.Cyan), string.Format(loader.GetString("DailyDetailsTemp"), doubles0.Count), Temperature.GetFormat(TemperatureDecoratorConverter.Parameter), -280, 9999, sb.ToString()));
                }
                if (doubles2 != null && doubles2.Count > 1)
                {
                    GetDailyXText(doubles2, sb);
                    Forecasts.Add(new GraphViewModel(doubles2, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("DailyDetailsPop"), doubles2.Count), "%", 0, 100, sb.ToString()));
                }
                if (doubles3 != null && doubles3.Count > 1)
                {
                    GetDailyXText(doubles3, sb);
                    Forecasts.Add(new GraphViewModel(doubles3, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("DailyDetailsPrep"), doubles3.Count), "mm", 0, 100, sb.ToString()));
                }
                if (doubles5 != null && doubles5.Count > 1)
                {
                    GetDailyXText(doubles5, sb);
                    Forecasts.Add(new GraphViewModel(doubles5, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("DailyDetailsVis"), doubles5.Count), Length.GetFormat(VisibilityConverter.LengthParameter), 0, 1000, sb.ToString()));
                }
                if (doubles4 != null && doubles4.Count > 1)
                {
                    GetDailyXText(doubles4, sb);
                    Forecasts.Add(new GraphViewModel(doubles4, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("DailyDetailsWind"), doubles4.Count), Wind.GetSpeedFormat(WindSpeedConverter.SpeedParameter), 0, 1000, sb.ToString()));
                }
            }

            OnFetchDataComplete();
        }
Exemplo n.º 17
0
        private static async Task Tick(string leagueDbName)
        {
            // Load statistic sets and check for recalculation interval
            using (var dbContext = new LeagueDbContext(leagueDbName))
            {
                var statisticSets      = dbContext.Set <StatisticSetEntity>().ToList();
                var checkStatisticSets = statisticSets.Where(x => IsDueTick(x.UpdateTime, TimeSpanConverter.Convert(x.UpdateInterval))).OrderBy(x => GetTypePriority(x));


                dbContext.Configuration.LazyLoadingEnabled = false;
                foreach (var statisticSet in checkStatisticSets)
                {
                    await statisticSet.CheckRequireRecalculationAsync(dbContext);

                    if (statisticSet.RequiresRecalculation)
                    {
                        await statisticSet.LoadRequiredDataAsync(dbContext);

                        statisticSet.Calculate(dbContext);
                    }
                }
                dbContext.Configuration.LazyLoadingEnabled = true;
                dbContext.SaveChanges();
            }
            GC.Collect();
        }
Exemplo n.º 18
0
 public void ConvertThrowsExceptionWhenValueIsNotTimeSpan()
 {
     _converter.Convert("-ss", 0);
 }