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 CanCalculateWindowOneDayBeforeRelativeDate( [ValueSource("SampleDates")]DateTime today, [ValueSource("SampleRelativeAmounts")]int relativeAmount, [ValueSource("AllDateInvervals")]DateInterval relativeInterval) { var startBound = DateRangeBound.CreateWindowBound(1, DateInterval.Day); var endBound = DateRangeBound.CreateRelativeBound(relativeAmount, relativeInterval); var range = new DateRange(startBound, endBound); Expect(range.GetStartDate(today), Is.EqualTo(range.GetEndDate(today).Value.AddDays(-1)), "A starting window range of 1 day should always produce one day before the end"); }
public object FormatDateRange(DateRangeBoundJsonTransferObject start, DateRangeBoundJsonTransferObject end) { DateRangeBound startRangeBound; DateRangeBound endRangeBound; try { startRangeBound = DateRangeBound.Parse(start.value, start.specificDate, start.windowAmount, start.windowInterval); endRangeBound = DateRangeBound.Parse(end.value, end.specificDate, end.windowAmount, end.windowInterval); } catch (ArgumentNullException exc) { return(new { isError = true, message = Localization.GetString("Missing " + exc.ParamName, ResourceFileRoot) }); } var dateRange = new DateRange(startRangeBound, endRangeBound); if (!string.IsNullOrEmpty(dateRange.ErrorMessage)) { return(new { isError = true, message = Localization.GetString(dateRange.ErrorMessage, ResourceFileRoot) }); } var dateRangeResourceKey = startRangeBound.IsUnbounded && endRangeBound.IsUnbounded ? "Date Range Without Bounds.Text" : startRangeBound.IsUnbounded ? "Date Range Without Start.Format" : endRangeBound.IsUnbounded ? "Date Range Without End.Format" : "Date Range.Format"; var dateRangeText = string.Format( CultureInfo.CurrentCulture, Localization.GetString(dateRangeResourceKey, ResourceFileRoot), dateRange.GetStartDate(), dateRange.GetEndDate()); #if DEBUG dateRangeText = dateRangeText.Replace("[L]", string.Empty); #endif return(new { isError = false, message = dateRangeText }); }
public object FormatDateRange(DateRangeBoundJsonTransferObject start, DateRangeBoundJsonTransferObject end) { DateRangeBound startRangeBound; DateRangeBound endRangeBound; try { startRangeBound = DateRangeBound.Parse(start.value, start.specificDate, start.windowAmount, start.windowInterval); endRangeBound = DateRangeBound.Parse(end.value, end.specificDate, end.windowAmount, end.windowInterval); } catch (ArgumentNullException exc) { return new { isError = true, message = Localization.GetString("Missing " + exc.ParamName, ResourceFileRoot) }; } var dateRange = new DateRange(startRangeBound, endRangeBound); if (!string.IsNullOrEmpty(dateRange.ErrorMessage)) { return new { isError = true, message = Localization.GetString(dateRange.ErrorMessage, ResourceFileRoot) }; } var dateRangeResourceKey = startRangeBound.IsUnbounded && endRangeBound.IsUnbounded ? "Date Range Without Bounds.Text" : startRangeBound.IsUnbounded ? "Date Range Without Start.Format" : endRangeBound.IsUnbounded ? "Date Range Without End.Format" : "Date Range.Format"; var dateRangeText = string.Format( CultureInfo.CurrentCulture, Localization.GetString(dateRangeResourceKey, ResourceFileRoot), dateRange.GetStartDate(), dateRange.GetEndDate()); #if DEBUG dateRangeText = dateRangeText.Replace("[L]", string.Empty); #endif return new { isError = false, message = dateRangeText }; }
public void CanCalculateWindowOneMonthAfterRelativeDate( [ValueSource("SampleDates")]DateTime today, [ValueSource("SampleRelativeAmounts")]int relativeAmount, [ValueSource("AllDateInvervals")]DateInterval relativeInterval) { var startBound = DateRangeBound.CreateRelativeBound(relativeAmount, relativeInterval); var endBound = DateRangeBound.CreateWindowBound(1, DateInterval.Month); var range = new DateRange(startBound, endBound); Expect(range.GetEndDate(today), Is.EqualTo(range.GetStartDate(today).Value.AddMonths(1)), "An ending window range of 1 month should always produce one month after the start"); }
public void CanCalculateWindowTenYearsBeforeSpecificDate([ValueSource("SampleDates")]DateTime today) { var startBound = DateRangeBound.CreateWindowBound(10, DateInterval.Year); var endBound = DateRangeBound.CreateSpecificDateBound(today); var range = new DateRange(startBound, endBound); Expect(range.GetStartDate(DateTime.MinValue), Is.EqualTo(today.AddYears(-10)), "A starting window range of 10 years should always produce ten years before the end"); }
public void CanCalculateRelativeStartDateForYesterday([ValueSource("SampleDates")]DateTime today, [ValueSource("DayBeforeSampleDates")]DateTime yesterday) { var startBound = DateRangeBound.CreateRelativeBound(-1, DateInterval.Day); var endBound = DateRangeBound.CreateUnboundedBound(); var range = new DateRange(startBound, endBound); Expect(range.GetStartDate(today), Is.EqualTo(yesterday), "A relative range of -1 day should always produce the day before 'today'"); }
public void CanCalculateRelativeStartDateForTomorrow([ValueSource("SampleDates")]DateTime today, [ValueSource("DayAfterSampleDates")]DateTime tomorrow) { var startBound = DateRangeBound.CreateRelativeBound(1, DateInterval.Day); var endBound = DateRangeBound.CreateUnboundedBound(); var range = new DateRange(startBound, endBound); Expect(range.GetStartDate(today), Is.EqualTo(tomorrow), "A relative range of 1 day should always produce the day after 'today'"); }
public void CanCalculateRelativeStartDateForToday([ValueSource("SampleDates")]DateTime today) { var startBound = DateRangeBound.CreateRelativeBound(0, DateInterval.Day); var endBound = DateRangeBound.CreateUnboundedBound(); var range = new DateRange(startBound, endBound); Expect(range.GetStartDate(today), Is.EqualTo(today), "A relative range of zero days should always produce today"); }
public void CanCalculateRelativeStartDateForThisYear([ValueSource("SampleDates")]DateTime today) { var startBound = DateRangeBound.CreateRelativeBound(0, 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.Year), "A relative range of zero years should always produce the same year"); 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 produce January 1"); }
public void CanCalculateRelativeStartDateForNextMonth([ValueSource("SampleDates")]DateTime today) { var startBound = DateRangeBound.CreateRelativeBound(1, 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.AddMonths(1).Year), "A relative range of 1 month should always produce the month after 'today'"); Expect(startDate.Value.Month, Is.EqualTo(today.AddMonths(1).Month), "A relative range of 1 month should always produce the month after 'today'"); Expect(startDate.Value.Day, Is.EqualTo(1), "A starting relative range of 1 month should always produce the first day of the month"); }