/// <summary> /// Gets a list of the <see cref="Event"/>s for this module. Does not take the <paramref name="listTag"/> or <paramref name="context"/> into account, /// effectively only supporting one data source. /// </summary> /// <remarks> /// The <paramref name="context"/> parameter should always be <c>null</c> unless the Engage:List tag is nested inside of another Engage:List. /// </remarks> /// <param name="listTag">The Engage:List <see cref="Tag"/> for which to return a data source</param> /// <param name="context">The current <see cref="Event"/> being processed, or <c>null</c> if no list is currently being processed</param> /// <returns>A list of the <see cref="Event"/>s over which the given <paramref name="listTag"/> should be processed</returns> private IEnumerable <ITemplateable> GetEvents(Tag listTag, ITemplateable context) { var dateRange = this.IsManageEvents ? new DateRange(DateRangeBound.CreateUnboundedBound(), DateRangeBound.CreateUnboundedBound()) : ModuleSettings.GetDateRangeFor(this); var events = EventCollection.Load( this.PortalId, dateRange.GetStartDateUtc(), dateRange.GetEndDateUtc(), this.SortExpression, this.CurrentPageIndex - 1, this.RecordsPerPage, this.Status.Equals("All", StringComparison.OrdinalIgnoreCase), !this.IsManageEvents && this.IsFeatured, !this.IsManageEvents && this.HideFullEvents, IsLoggedIn ? this.UserInfo.Email : null, this.FilterCategoryIds ?? this.CategoryIds); this.TotalNumberOfEvents = events.TotalRecords; this.TemplateProvider.ItemPagingState = new ItemPagingState(this.CurrentPageIndex, events.TotalRecords, this.RecordsPerPage); return(((IEnumerable <Event>)events).Select(e => { if (string.IsNullOrEmpty(e.Category.Name)) { e.Category.Name = this.Localize("DefaultCategory", this.LocalSharedResourceFile); } return (ITemplateable)e; })); }
private static int WriteDateRangeBound(byte[] buffer, int offset, DateRangeBound value) { var millis = Convert.ToInt64(Math.Floor((value.Timestamp - UnixStart).TotalMilliseconds)); EndianBitConverter.SetBytes(false, buffer, offset, millis); buffer[offset + 8] = (byte)value.Precision; return(offset + 9); }
public void TwoUnboundedAreValid() { var startBound = DateRangeBound.CreateUnboundedBound(); var endBound = DateRangeBound.CreateUnboundedBound(); var range = new DateRange(startBound, endBound); Expect(range.IsValid, Is.True, "A range from unbounded to unbounded is always valid"); }
public void CanCalculateWindowTenMonthsBeforeSpecificDate([ValueSource("SampleDates")] DateTime today) { var startBound = DateRangeBound.CreateWindowBound(10, DateInterval.Month); var endBound = DateRangeBound.CreateSpecificDateBound(today); var range = new DateRange(startBound, endBound); Expect(range.GetStartDate(DateTime.MinValue), Is.EqualTo(today.AddMonths(-10)), "A starting window range of 10 months should always produce ten months before the end"); }
public void CanCalculateWindowOneMonthAfterSpecificDate([ValueSource("SampleDates")] DateTime today) { var startBound = DateRangeBound.CreateSpecificDateBound(today); var endBound = DateRangeBound.CreateWindowBound(1, DateInterval.Month); var range = new DateRange(startBound, endBound); Expect(range.GetEndDate(DateTime.MinValue), Is.EqualTo(today.AddMonths(1)), "An ending window range of 1 month should always produce one month after the start"); }
public void CanCalculateRelativeEndDateForYesterday([ValueSource("SampleDates")] DateTime today, [ValueSource("DayBeforeSampleDates")] DateTime yesterday) { var startBound = DateRangeBound.CreateUnboundedBound(); var endBound = DateRangeBound.CreateRelativeBound(-1, DateInterval.Day); var range = new DateRange(startBound, endBound); Expect(range.GetEndDate(today), Is.EqualTo(yesterday), "A relative range of -1 day should always produce the day before 'today'"); }
public void Constructor_Sets_UpperBound_To_Null_Test() { var lowerBound = new DateRangeBound(DateTimeOffset.UtcNow, DateRangePrecision.Second); var value = new DateRange(lowerBound); Assert.AreEqual(null, value.UpperBound); Assert.AreEqual(lowerBound, value.LowerBound); }
public void CanCalculateWindowOneDayBeforeSpecificDate([ValueSource("SampleDates")] DateTime today) { var startBound = DateRangeBound.CreateWindowBound(1, DateInterval.Day); var endBound = DateRangeBound.CreateSpecificDateBound(today); var range = new DateRange(startBound, endBound); Expect(range.GetStartDate(DateTime.MinValue), Is.EqualTo(today.AddDays(-1)), "A starting window range of 1 day should always produce one day before the end"); }
public void CanCalculateRelativeEndDateForToday([ValueSource("SampleDates")] DateTime today) { var startBound = DateRangeBound.CreateUnboundedBound(); var endBound = DateRangeBound.CreateRelativeBound(0, DateInterval.Day); var range = new DateRange(startBound, endBound); Expect(range.GetEndDate(today), Is.EqualTo(today), "A relative range of zero days should always produce today"); }
public void CanCalculateRelativeEndDateForTomorrow([ValueSource("SampleDates")] DateTime today, [ValueSource("DayAfterSampleDates")] DateTime tomorrow) { var startBound = DateRangeBound.CreateUnboundedBound(); var endBound = DateRangeBound.CreateRelativeBound(1, DateInterval.Day); var range = new DateRange(startBound, endBound); Expect(range.GetEndDate(today), Is.EqualTo(tomorrow), "A relative range of 1 day should always produce the day after 'today'"); }
public void CanCalculateWindowTenDaysAfterSpecificDate([ValueSource("SampleDates")] DateTime today) { var startBound = DateRangeBound.CreateSpecificDateBound(today); var endBound = DateRangeBound.CreateWindowBound(10, DateInterval.Day); var range = new DateRange(startBound, endBound); Expect(range.GetEndDate(DateTime.MinValue), Is.EqualTo(today.AddDays(10)), "An ending window range of 10 days should always produce ten days after the start"); }
private static int WriteDateRangeBound(byte[] buffer, int offset, DateRangeBound value) { var ticksDiff = value.Timestamp.Ticks - UnixStart.Ticks; var millisecondsDiff = ticksDiff / (decimal)TimeSpan.TicksPerMillisecond; var millis = Convert.ToInt64(Math.Floor(millisecondsDiff)); EndianBitConverter.SetBytes(false, buffer, offset, millis); buffer[offset + 8] = (byte)value.Precision; return(offset + 9); }
public void EndWindowIsInvalidWithUnboundedStart( [ValueSource("SampleWindowAmounts")] int endAmount, [ValueSource("AllDateInvervals")] DateInterval endInterval) { var startBound = DateRangeBound.CreateUnboundedBound(); var endBound = DateRangeBound.CreateWindowBound(endAmount, endInterval); var range = new DateRange(startBound, endBound); this.Expect(range.ErrorMessage, Is.EqualTo("Window to Beginning of Time"), "A range from unbounded to window is always invalid"); }
public void EndWindowIsValidWithStartingSpecific( [ValueSource("SampleDates")] DateTime starting, [ValueSource("SampleWindowAmounts")] int endAmount, [ValueSource("AllDateInvervals")] DateInterval endInterval) { var startBound = DateRangeBound.CreateSpecificDateBound(starting); var endBound = DateRangeBound.CreateWindowBound(endAmount, endInterval); var range = new DateRange(startBound, endBound); Expect(range.IsValid, Is.True, "A range from specific to window is always valid"); }
public void CanCalculateWindowTenYearsAfterRelativeDate( [ValueSource("SampleDates")] DateTime today, [ValueSource("SampleRelativeAmounts")] int relativeAmount, [ValueSource("AllDateInvervals")] DateInterval relativeInterval) { var startBound = DateRangeBound.CreateRelativeBound(relativeAmount, relativeInterval); var endBound = DateRangeBound.CreateWindowBound(10, DateInterval.Year); var range = new DateRange(startBound, endBound); Expect(range.GetEndDate(today), Is.EqualTo(range.GetStartDate(today).Value.AddYears(10)), "An ending window range of 10 years should always produce ten years after the start"); }
public void CanCalculateWindowOneYearBeforeRelativeDate( [ValueSource("SampleDates")] DateTime today, [ValueSource("SampleRelativeAmounts")] int relativeAmount, [ValueSource("AllDateInvervals")] DateInterval relativeInterval) { var startBound = DateRangeBound.CreateWindowBound(1, DateInterval.Year); var endBound = DateRangeBound.CreateRelativeBound(relativeAmount, relativeInterval); var range = new DateRange(startBound, endBound); Expect(range.GetStartDate(today), Is.EqualTo(range.GetEndDate(today).Value.AddYears(-1)), "A starting window range of 1 year should always produce one year before the end"); }
public void StartWindowIsValidWithEndingSpecific( [ValueSource("SampleWindowAmounts")] int startAmount, [ValueSource("AllDateInvervals")] DateInterval startInterval, [ValueSource("SampleDates")] DateTime endingDate) { var startBound = DateRangeBound.CreateWindowBound(startAmount, startInterval); var endBound = DateRangeBound.CreateSpecificDateBound(endingDate); var range = new DateRange(startBound, endBound); Expect(range.IsValid, Is.True, "A range from window to specific is always valid"); }
public void StartWindowIsValidWithEndingRelative( [ValueSource("SampleWindowAmounts")] int startAmount, [ValueSource("AllDateInvervals")] DateInterval startInterval, [ValueSource("SampleRelativeAmounts")] int endWindow, [ValueSource("AllDateInvervals")] DateInterval endInterval) { var startBound = DateRangeBound.CreateWindowBound(startAmount, startInterval); var endBound = DateRangeBound.CreateRelativeBound(endWindow, endInterval); var range = new DateRange(startBound, endBound); Expect(range.IsValid, Is.True, "A range from window to relative is always valid"); }
public void TwoWindowsAreInvalid( [ValueSource("SampleWindowAmounts")] int startAmount, [ValueSource("AllDateInvervals")] DateInterval startInterval, [ValueSource("SampleWindowAmounts")] int endAmount, [ValueSource("AllDateInvervals")] DateInterval endInterval) { var startBound = DateRangeBound.CreateWindowBound(startAmount, startInterval); var endBound = DateRangeBound.CreateWindowBound(endAmount, endInterval); var range = new DateRange(startBound, endBound); Expect(range.ErrorMessage, Is.EqualTo("Both Window"), "A range from window to window is always invalid"); }
public void Equality_Tests() { var d1 = new DateTimeOffset(1999, 12, 31, 23, 59, 59, TimeSpan.FromHours(0)); var boundary1 = new DateRangeBound(d1, DateRangePrecision.Millisecond); Assert.True(boundary1 == new DateRangeBound(d1, DateRangePrecision.Millisecond)); Assert.True(boundary1.Equals(new DateRangeBound(d1, DateRangePrecision.Millisecond))); Assert.False(boundary1 == new DateRangeBound(d1, DateRangePrecision.Second)); Assert.True(boundary1 != new DateRangeBound(d1, DateRangePrecision.Second)); Assert.False(boundary1.Equals(new DateRangeBound(d1, DateRangePrecision.Second))); Assert.False(boundary1.Equals(null)); }
public void CanCalculateRelativeStartDateForLastYear([ValueSource("SampleDates")] DateTime today) { var startBound = DateRangeBound.CreateRelativeBound(-1, DateInterval.Year); var endBound = DateRangeBound.CreateUnboundedBound(); var range = new DateRange(startBound, endBound); var startDate = range.GetStartDate(today); Expect(startDate.HasValue, Is.True, "Should have a start date"); Expect(startDate.Value.Year, Is.EqualTo(today.AddYears(-1).Year), "A relative range of -1 years should always produce the year before 'today'"); Expect(startDate.Value.Month, Is.EqualTo(1), "A starting relative range of years should always produce January"); Expect(startDate.Value.Day, Is.EqualTo(1), "A starting relative range of years should always produce January 1"); }
public void CanCalculateRelativeEndDateForNextMonth([ValueSource("SampleDates")] DateTime today) { var startBound = DateRangeBound.CreateUnboundedBound(); var endBound = DateRangeBound.CreateRelativeBound(1, DateInterval.Month); var range = new DateRange(startBound, endBound); var endDate = range.GetEndDate(today); Expect(endDate.HasValue, Is.True, "Should have a start date"); Expect(endDate.Value.Year, Is.EqualTo(today.AddMonths(1).Year), "A relative range of 1 month should always produce the month after 'today'"); Expect(endDate.Value.Month, Is.EqualTo(today.AddMonths(1).Month), "A relative range of 1 month should always produce the month after 'today'"); Expect(endDate.Value.Day, Is.EqualTo(GetLastDayOfMonth(today.AddMonths(1)).Day), "A relative range of 1 month should always produce the last day of the month after 'today'"); }
public void CanCalculateRelativeStartDateForThisMonth([ValueSource("SampleDates")] DateTime today) { var startBound = DateRangeBound.CreateRelativeBound(0, DateInterval.Month); var endBound = DateRangeBound.CreateUnboundedBound(); var range = new DateRange(startBound, endBound); var startDate = range.GetStartDate(today); Expect(startDate.HasValue, Is.True, "Should have a start date"); Expect(startDate.Value.Year, Is.EqualTo(today.Year), "A relative range of zero months should always produce the same year"); Expect(startDate.Value.Month, Is.EqualTo(today.Month), "A relative range of zero months should always produce the same month"); Expect(startDate.Value.Day, Is.EqualTo(1), "A starting relative range of zero months should produce the first day of the month"); }
public void CanCalculateRelativeEndDateForNextYear([ValueSource("SampleDates")] DateTime today) { var startBound = DateRangeBound.CreateUnboundedBound(); var endBound = DateRangeBound.CreateRelativeBound(1, DateInterval.Year); var range = new DateRange(startBound, endBound); var endDate = range.GetEndDate(today); Expect(endDate.HasValue, Is.True, "Should have a start date"); Expect(endDate.Value.Year, Is.EqualTo(today.AddYears(1).Year), "A relative range of 1 year should always produce the year after 'today'"); Expect(endDate.Value.Month, Is.EqualTo(12), "An ending relative range of years should always produce December"); Expect(endDate.Value.Day, Is.EqualTo(31), "An ending relative range of years should always produce December 31"); }
/// <summary> /// Gets the search items for the given module. /// </summary> /// <param name="modInfo">The module for which to get search items.</param> /// <returns>A new <see cref="SearchItemInfoCollection"/> for the items in the module</returns> public SearchItemInfoCollection GetSearchItems(ModuleInfo modInfo) { if (modInfo == null) { throw new ArgumentNullException("modInfo"); } var detailDisplayTabId = ModuleSettings.DetailsDisplayTabId.GetValueAsInt32For(Utility.DesktopModuleName, modInfo, ModuleSettings.DetailsDisplayTabId.DefaultValue); var detailDisplayModuleId = ModuleSettings.DetailsDisplayModuleId.GetValueAsInt32For(Utility.DesktopModuleName, modInfo, ModuleSettings.DetailsDisplayModuleId.DefaultValue); if ((detailDisplayTabId != null && detailDisplayTabId != modInfo.TabID) || detailDisplayModuleId == null) { // If it's set to display on another page, just show it in this module; there's no way to link a search result to another page detailDisplayModuleId = modInfo.ModuleID; } var isListingDisplay = ModuleSettings.DisplayType.GetValueAsStringFor(Utility.DesktopModuleName, modInfo, ModuleSettings.DisplayType.DefaultValue).Equals("LIST", StringComparison.OrdinalIgnoreCase); var dateRange = isListingDisplay ? ModuleSettings.GetDateRangeFor(new FakeModuleControlBase(Utility.DesktopModuleName, modInfo)) : new DateRange(DateRangeBound.CreateUnboundedBound(), DateRangeBound.CreateUnboundedBound()); var featuredOnly = ModuleSettings.FeaturedOnly.GetValueAsBooleanFor(Utility.DesktopModuleName, modInfo, ModuleSettings.FeaturedOnly.DefaultValue); var hideFullEvents = ModuleSettings.HideFullEvents.GetValueAsBooleanFor(Utility.DesktopModuleName, modInfo, ModuleSettings.HideFullEvents.DefaultValue); var categoriesSettingValue = ModuleSettings.Categories.GetValueAsStringFor(Utility.DesktopModuleName, modInfo, ModuleSettings.Categories.DefaultValue); var categoryIds = string.IsNullOrEmpty(categoriesSettingValue) ? Enumerable.Empty <int>() : categoriesSettingValue.Split(',').Select(id => int.Parse(id, CultureInfo.InvariantCulture)); var querystringParameters = new[] { "modId=" + detailDisplayModuleId.Value.ToString(CultureInfo.InvariantCulture), "key=EventDetail" }; var events = EventCollection.Load( modInfo.PortalID, dateRange.GetStartDateUtc(), dateRange.GetEndDateUtc(), isListingDisplay, featuredOnly, hideFullEvents, null, categoryIds); return(new SearchItemInfoCollection(events.Cast <Event>() .Select(e => new SearchItemInfo( e.Title, e.Overview, e.CreatedBy, e.RevisionDate, modInfo.ModuleID, e.Id.ToString(CultureInfo.InvariantCulture), e.Title + ' ' + e.Overview + ' ' + e.Description, string.Join("&", Utility.GetEventParameters(e, querystringParameters).ToArray()))) .ToArray())); }
private static DateRange GetRange( DateTimeOffset?d1, Precision?precision1, DateTimeOffset?d2 = null, Precision?precision2 = null) { var lowerBound = DateRangeBound.Unbounded; if (d1 != null && precision1 != null) { lowerBound = new DateRangeBound(d1.Value, precision1.Value); } if (d2 == null || precision2 == null) { return(new DateRange(lowerBound)); } return(new DateRange(lowerBound, new DateRangeBound(d2.Value, precision2.Value))); }
/// <summary> /// Sets the initial values of the controls for a date range bound. /// </summary> /// <param name="bound">The bound to load</param> /// <param name="rangeBoundList">The main range bound list.</param> /// <param name="specificDatePicker">The picker for the specific date.</param> /// <param name="windowAmountTextBox">The text box for the window amount.</param> /// <param name="windowIntervalList">The window interval list.</param> private void LoadBoundSettings(DateRangeBound bound, ListControl rangeBoundList, RadDatePicker specificDatePicker, RadNumericTextBox windowAmountTextBox, ListControl windowIntervalList) { Utility.LocalizeListControl(rangeBoundList, this.LocalResourceFile); Utility.LocalizeListControl(windowIntervalList, this.LocalResourceFile); SelectListValue(rangeBoundList, DateRangeBoundJsonTransferObject.GetListValueForBound(bound)); if (bound.IsSpecificDate) { specificDatePicker.SelectedDate = bound.SpecificDate; } else if (bound.IsWindow) { windowAmountTextBox.Value = bound.WindowAmount; SelectListValue(windowIntervalList, bound.WindowInterval.Value.ToString()); } }
public void Parse_ToString_Test() { var arr = new[] { "2017-01-20T06:24:57.123Z", "2017-01-20T06", "2017", "1234-07", "1234-07-02T18:01", "0001", "*" }; foreach (var boundaryString in arr) { var value = DateRangeBound.Parse(boundaryString); Assert.AreEqual(boundaryString, value.ToString()); } }
/// <summary> /// Parses the form's input into a date range. /// </summary> /// <returns>A <see cref="DateRange"/> instance</returns> private DateRange ParseInputToDateRange() { if (this.parsedDateRange == null) { var startRangeBound = DateRangeBound.Parse( this.RangeStartDropDownList.SelectedValue, this.StartSpecificDatePicker.SelectedDate, this.StartWindowAmountTextBox.Value, this.StartWindowIntervalDropDownList.SelectedValue); var endRangeBound = DateRangeBound.Parse( this.RangeEndDropDownList.SelectedValue, this.EndSpecificDatePicker.SelectedDate, this.EndWindowAmountTextBox.Value, this.EndWindowIntervalDropDownList.SelectedValue); this.parsedDateRange = new DateRange(startRangeBound, endRangeBound); } return(this.parsedDateRange); }