public void TestSubtractMultipleMonthsWhenOneMonthHas30Days() { const string expected = "2015-11-01"; var actual = DateMath.Parse("2016-01-01||-2M", Format); Assert.AreEqual(expected, actual); }
public void TestNow() { var expected = DateTime.UtcNow.ToString(Format); var actual = DateMath.Parse("now", Format); Assert.AreEqual(expected, actual); }
/// <summary> /// Returns maximum value of gap /// </summary> /// <param name="facetType">Facet type</param> /// <param name="minimumValue">Minimum value of gap</param> /// <param name="gapValue">Gap of the facet range</param> /// <returns></returns> private object CalculateMaximumValue(Type facetType, JToken minimumValue, object gapValue) { var value = minimumValue.ToObject(facetType); if (facetType == typeof(float)) { return(((float)value) + Convert.ToSingle(gapValue)); } if (facetType == typeof(decimal)) { return(((decimal)value) + Convert.ToDecimal(gapValue)); } if (facetType == typeof(DateTime)) { return(DateMath.Apply((DateTime)value, (string)gapValue)); } if (facetType == typeof(long)) { return(((long)value) + Convert.ToInt64(gapValue)); } return(((int)value) + Convert.ToInt32(gapValue)); }
public void TestAddMinute() { const string expected = "2016-12-01 00:01:00"; var actual = DateMath.Parse("2016-12-01||+1m", FormatWithTime); Assert.AreEqual(expected, actual); }
public void TestOutOfOrder() { var expected = DateTime.UtcNow.AddDays(1.0).AddMinutes(1.0).AddSeconds(1.0); var actual = DateMath.Parse("now+1d+1s+1m"); Assert.AreEqual(expected.ToString(FormatWithTime), actual.ToString(FormatWithTime)); }
public void TestAddToNowWithARealDateTime() { var expected = DateTime.UtcNow.AddDays(3.0).AddHours(7.0); var actual = DateMath.Parse("now+3d+7h"); Assert.AreEqual(expected.ToString(FormatWithTime), actual.ToString(FormatWithTime)); }
public void TestAddMonth() { const string expected = "2016-12-01"; var actual = DateMath.Parse("2016-11-01||+1M", Format); Assert.AreEqual(expected, actual); }
protected override QueryContainer QueryFluent(QueryContainerDescriptor <Project> q) => q .DistanceFeature(rf => rf .Boost(1.1) .Field(f => f.StartedOn) .Origin(DateMath.FromString("now")) .Pivot(new Time("7d")) );
protected static object GetMaximumValue(Type fieldType, IFacetItemRangeValue item, string facetGap) { if (string.IsNullOrWhiteSpace(facetGap)) { return(null); } var appliedFacetGap = facetGap; if (DateTypes.Contains(fieldType)) { appliedFacetGap = GetDateTimeFacetGap(appliedFacetGap); var minimumValue = ((FacetItemRangeValue <DateTime>)item).MinimumValue; return(DateMath.Apply(minimumValue ?? DateTime.MinValue, appliedFacetGap)); } if (NotIntTypes.Contains(fieldType)) { var minimumValueDecimal = ((FacetItemRangeValue <decimal>)item).MinimumValue; return((minimumValueDecimal ?? decimal.MinValue) + decimal.Parse(appliedFacetGap, CultureInfo.InvariantCulture)); } var minimumValueINt = ((FacetItemRangeValue <int>)item).MinimumValue; return((minimumValueINt ?? int.MinValue) + int.Parse(appliedFacetGap, CultureInfo.InvariantCulture)); }
public void TestAddLeapYearAndNormalYear() { const string expected = "2017-12-01"; var actual = DateMath.Parse("2015-12-01||+2y", Format); Assert.AreEqual(expected, actual); }
public void TestSubtractLeapYear() { const string expected = "2016-12-01"; var actual = DateMath.Parse("2017-12-01||-1y", Format); Assert.AreEqual(expected, actual); }
public void TestAddMultipleMonthsWhenOneMonthHas29Days() { const string expected = "2016-04-01"; var actual = DateMath.Parse("2016-02-01||+2M", Format); Assert.AreEqual(expected, actual); }
public void TestAddMonthWhenMonthHas29Days() { const string expected = "2016-03-01"; var actual = DateMath.Parse("2016-02-01||+1M", Format); Assert.AreEqual(expected, actual); }
public void TestSubtractMonthWhenMonthHas31Days() { const string expected = "2016-10-01"; var actual = DateMath.Parse("2016-11-01||-1M", Format); Assert.AreEqual(expected, actual); }
public void DateMathApplySomeOperatorsAndRounding() { var date = new DateTime(2016, 6, 6, 0, 0, 0); var juneFirst = DateMath.Apply(date, "+1d+9h+10m/h"); Assert.AreEqual("2016-06-07 09:00:00", juneFirst.ToString("yyyy-MM-dd HH:mm:ss")); }
public void TestAddTwoSeconds() { const string expected = "2016-12-01 00:00:02"; var actual = DateMath.Parse("2016-12-01||+2s", FormatWithTime); Assert.AreEqual(expected, actual); }
public void TestAddToNow() { var expected = DateTime.UtcNow.AddDays(3.0).AddHours(7.0).ToString(Format); var actual = DateMath.Parse("now+3d+7h", Format); Assert.AreEqual(expected, actual); }
public void TestAddCombo() { const string expected = "2016-12-01 01:02:03"; var actual = DateMath.Parse("2016-12-01||+1h+2m+3s", FormatWithTime); Assert.AreEqual(expected, actual); }
public void TestABadDate() { const string expected = "201x-11-01||"; var actual = DateMath.Parse("201x-11-01||", Format); Assert.AreEqual(expected, actual); }
public void TestSubtract() { const string expected = "2016-12-31 23:59:59"; var actual = DateMath.Parse("2017-01-01||-1s", FormatWithTime); Assert.AreEqual(expected, actual); }
public void TestAddDay() { const string expected = "2016-11-21"; var actual = DateMath.Parse("2016-11-20||+1d", Format); Assert.AreEqual(expected, actual); }
public void DateMathApplyRoundToMinute() { var date = new DateTime(2016, 6, 7, 9, 10, 11); var juneFirst = DateMath.Apply(date, "/m"); Assert.AreEqual("2016-06-07 09:10:00", juneFirst.ToString("yyyy-MM-dd HH:mm:ss")); }
private void refreshDates() { // update the BegindDate / EndDate DateTime begin = this.BeginDate; if (this.Tasks.Count(t => t.SignificantDate.HasValue && t.SignificantDate < DateTime.MaxValue.Date) > 0) { begin = this.Tasks.Where(t => t.SignificantDate.HasValue && t.SignificantDate < DateTime.MaxValue.Date).Min(t => t.SignificantDate.Value); } DateTime end = this.EndDate; if (this.Tasks.Count(t => t.SignificantDate.HasValue && t.SignificantDate < DateTime.MaxValue.Date) > 0) { end = this.Tasks.Where(t => t.SignificantDate.HasValue && t.SignificantDate < DateTime.MaxValue.Date).Max(t => t.SignificantDate.Value); } // adjust the dates (we want to get the range of dates for all of the visible data but always show at least 1 month // in the past and 1 month the future. we won't show events more than 1 year in the past or 1 year in the future begin = DateMath.Min(begin, DateTime.Today.AddMonths(-2)); begin = DateMath.Max(begin, DateTime.Today.AddYears(-1)); end = DateMath.Max(end, DateTime.Today.AddMonths(2)); end = DateMath.Min(end, DateTime.Today.AddYears(1)); // set the props this.BeginDate = begin; this.EndDate = end; // calculate the width of the panel // generate a collection of dates that we can use to populate // the labels on our timeline m_dates.Clear(); m_months.Clear(); DateTime date = begin; m_months.Add(new DateTime(date.Year, date.Month, 1)); while (date <= end) { m_dates.Add(date); date = date.AddDays(1); if (date.Day == 1) { m_months.Add(new DateTime(date.Year, date.Month, 1)); } } }
private static QueryFilter MakeDateFilter(IFilterable filterable, PropertyInfo propertyInfo) { var borders = propertyInfo.GetValue(filterable).ToString().Split(','); return(new DateRangeQueryFilter() { FieldName = propertyInfo.Name.ToCamelCase(), Min = DateMath.FromString(borders[0]), Max = DateMath.FromString(borders[1]) }); }
protected override QueryContainer QueryFluent(QueryContainerDescriptor <Project> q) => q .DateRange(c => c .Name("named_query") .Boost(1.1) .Field(p => p.Description) .GreaterThan(FixedDate) .GreaterThanOrEquals(DateMath.Anchored(FixedDate).RoundTo(TimeUnit.Month)) .LessThan("01/01/2012") .LessThanOrEquals(DateMath.Now) .Format("dd/MM/yyyy||yyyy") .TimeZone("+01:00") );
// Use this for initialization void Start() { JSONUtils.initJsonObjectConversion(); System.DateTime date = System.DateTime.Now; for (int i = 0; i < 5; ++i) { date = date.AddMinutes(-6); StartCoroutine(getMatchIDList(DateMath.RoundDateToFive(date))); } }
public void TestReadMe() { const string input = "2016-12-31 1 PM||"; Assert.AreEqual("2016-12-31 1 PM", DateMath.Parse(input, "yyyy-MM-dd h tt")); Assert.AreEqual("2017-01-01 12 AM", DateMath.Parse(input + "+11h", "yyyy-MM-dd h tt")); Assert.AreEqual("2017-12-31 23:59:59", DateMath.Parse(input + "-13h+1y+1d-1s", "yyyy-MM-dd HH:mm:ss")); Assert.AreEqual("2016-12-31 00:00:00.000", DateMath.Parse(input + "/d", "yyyy-MM-dd HH:mm:ss.fff")); var date = new DateTime(2016, 12, 31, 9, 30, 2); var newYears = DateMath.Apply(date, "+1d/y"); Assert.AreEqual("2017-01-01 00:00:00", newYears.ToString("yyyy-MM-dd HH:mm:ss")); }
public IActionResult GetHistogram(int id) { _logger.LogDebug("Elasitc url: {url}", _config.Value.MetricsDatabase); var connSetting = new ConnectionSettings(new Uri(_config.Value.MetricsDatabase)); connSetting.DisableDirectStreaming(true); var client = new ElasticClient(connSetting); var result = client.Search <Measument>(s => s.Index("measurement-*") .Size(1) .Sort(z => z.Descending(f => f.Timestamp)) .Query(q => q.DateRange(r => r.Field(f => f.Timestamp) .GreaterThan(DateMath.Anchored(DateTime.Now).Subtract("7d")) .LessThan(DateMath.Anchored(DateTime.Now)) ) && q.Term(t => t.Field(f => f.DeviceId).Value(id)) ) .Aggregations(a => a.DateHistogram("Temperature", t => t.Field(f => f.Timestamp) .Interval(DateInterval.Day) .Aggregations(x => x.Average("average", av => av.Field(fi => fi.Value))))) ); if (!result.IsValid) { _logger.LogError(result.DebugInformation); _logger.LogError(result.ServerError.Error.Reason); } _logger.LogDebug("Success: {success}", result.IsValid); var histogram = result.Aggs .DateHistogram("Temperature") .Buckets.Select(x => new MetricsBucket { Key = x.Date.Date.ToString("ddd MM-dd1"), Value = GetAverage(x) } ); return(new ObjectResult( new HistogramResult { DeviceId = id, CurrentTemperature = result.Documents.First().Value, Timestamp = result.Documents.First().Timestamp.ToString("yyyy-MM-dd hh:mm:ss"), Labels = histogram.Select(x => x.Key), Values = histogram.Select(x => x.Value) })); }
public async Task Test_ComplexSearch() { var searchModel = new SearchRequest <Employee>(Indices.Parse("megacorp")) { Query = new DateRangeQuery { Field = "age", GreaterThan = DateMath.FromString("30") } && new MatchQuery { Field = "last_name", Query = "smith" } }; var response = await Client.SearchAsync <Employee>(searchModel); Assert.True(response.Documents.Count == 1); }
public static QueryContainer MakeRangeQuery(string type, string gte, string lte, string field, double boost = 1) { QueryContainer rangeQuery = null; if (type.ToLower() == "long") { rangeQuery = new LongRangeQuery() { Field = field, LessThan = long.Parse(lte), GreaterThan = long.Parse(gte), Boost = boost }; } else if (type.ToLower() == "date") { rangeQuery = new DateRangeQuery() { Field = field, LessThan = DateMath.FromString(lte), GreaterThan = DateMath.FromString(gte), Boost = boost }; } else if (type.ToLower() == "term") { rangeQuery = new TermRangeQuery() { Field = field, LessThan = lte, GreaterThan = gte, Boost = boost }; } else if (type.ToLower() == "numeric") { rangeQuery = new TermRangeQuery() { Field = field, LessThan = lte, GreaterThan = gte, Boost = boost }; } return(rangeQuery); }