public void ShouldGetAllowedDateTimeRanges()
    {
        var schedule = Schedule
                       .On(new YearDay(4, 18), new YearDay(9, 7))
                       .At(TimeRange.From(10, 13).ForOneHour());
        var allowedDateTimeRanges = schedule.DateTimeRanges
                                    (
            DateRange.Between
            (
                new DateTime(2021, 9, 1),
                new DateTime(2021, 10, 11)
            )
                                    );

        Assert.That
        (
            allowedDateTimeRanges,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 9, 7, 10, 13, 0),
                new DateTime(2021, 9, 7, 11, 13, 0)
            )
        }
            )
        );
    }
示例#2
0
 public static DateRange Between(DateTime startDate, DateTime endDate)
 {
     if (startDate > DateTime.MinValue)
     {
         startDate = startDate.Date;
     }
     if (endDate < DateTime.MaxValue)
     {
         endDate = endDate.Date.AddDays(1).AddTicks(-1);
     }
     return(new DateRange(DateTimeRange.Between(startDate, endDate)));
 }
    public void ShouldBeInRange_WhenValueIsBetweenStartAndEnd()
    {
        var value     = DateTimeOffset.Now;
        var start     = value.AddHours(-1);
        var end       = value.AddHours(1);
        var timeRange = DateTimeRange.Between(start, end);

        Assert.That(timeRange.IsInRange(start), Is.True);
        Assert.That(timeRange.IsInRange(start.AddHours(-1)), Is.False);
        Assert.That(timeRange.IsInRange(value), Is.True);
        Assert.That(timeRange.IsInRange(end), Is.True);
        Assert.That(timeRange.IsInRange(end.AddHours(1)), Is.False);
    }
    public void ShouldGetAllowedDateTimeRanges()
    {
        var schedule = Schedule
                       .First(DayOfWeek.Monday)
                       .OfEveryMonth()
                       .AndTheThird(DayOfWeek.Wednesday)
                       .OfEveryMonth()
                       .AndTheLast(DayOfWeek.Saturday)
                       .OfEveryMonth()
                       .At(TimeRange.From(21, 0).ForOneHour());
        var ranges = schedule.DateTimeRanges
                     (
            DateRange.Between
            (
                new DateTime(2021, 9, 24),
                new DateTime(2021, 10, 21)
            )
                     );

        Assert.That
        (
            ranges,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 9, 25, 21, 0, 0),
                new DateTime(2021, 9, 25, 22, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 4, 21, 0, 0),
                new DateTime(2021, 10, 4, 22, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 20, 21, 0, 0),
                new DateTime(2021, 10, 20, 22, 0, 0)
            )
        }
            ),
            "Should get allowed date time ranges"
        );
    }
    public void ShouldGetAllowedDateTimeRanges()
    {
        var schedule = Schedule
                       .On(DayOfWeek.Monday, DayOfWeek.Friday)
                       .At(TimeRange.From(10, 13).ForOneHour());
        var allowedTimes = schedule.DateTimeRanges
                           (
            DateRange.Between
            (
                new DateTime(2021, 10, 1),
                new DateTime(2021, 10, 11)
            )
                           );

        Assert.That
        (
            allowedTimes,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 1, 10, 13, 0),
                new DateTime(2021, 10, 1, 11, 13, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 4, 10, 13, 0),
                new DateTime(2021, 10, 4, 11, 13, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 8, 10, 13, 0),
                new DateTime(2021, 10, 8, 11, 13, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 11, 10, 13, 0),
                new DateTime(2021, 10, 11, 11, 13, 0)
            )
        }
            )
        );
    }
示例#6
0
    public void ShouldGetAllowedDateTimeRanges()
    {
        var schedule = Schedule
                       .First(DayOfWeek.Monday).Of(Months.January)
                       .AndTheThird(DayOfWeek.Wednesday).Of(Months.June)
                       .AndTheLast(DayOfWeek.Saturday).Of(Months.October)
                       .At(TimeRange.From(21, 0).ForOneHour());
        var ranges = schedule.DateTimeRanges
                     (
            DateRange.Between
            (
                new DateTime(2021, 5, 1),
                new DateTime(2022, 2, 1)
            )
                     );

        Assert.That
        (
            ranges,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 6, 16, 21, 0, 0),
                new DateTime(2021, 6, 16, 22, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 30, 21, 0, 0),
                new DateTime(2021, 10, 30, 22, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2022, 1, 3, 21, 0, 0),
                new DateTime(2022, 1, 3, 22, 0, 0)
            )
        }
            ),
            "Should get allowed date time ranges"
        );
    }
    public void ShouldGetAllowedDates()
    {
        var schedule = Schedule
                       .Every(3).Months().Starting(new DateTime(2021, 10, 5))
                       .At(TimeRange.From(19, 35).ForOneHour());
        var allowedDateTimeRanges = schedule.DateTimeRanges
                                    (
            DateRange.Between
            (
                new DateTime(2021, 10, 1),
                new DateTime(2022, 4, 6)
            )
                                    );

        Assert.That
        (
            allowedDateTimeRanges,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 5, 19, 35, 0),
                new DateTime(2021, 10, 5, 20, 35, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2022, 1, 5, 19, 35, 0),
                new DateTime(2022, 1, 5, 20, 35, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2022, 4, 5, 19, 35, 0),
                new DateTime(2022, 4, 5, 20, 35, 0)
            )
        }
            )
        );
    }
示例#8
0
    public void ShouldGetDateTimeRanges()
    {
        var schedule = Schedule
                       .On(new MonthDay(1), new MonthDay(12), new MonthDay(15))
                       .At(TimeRange.From(22, 0).ForOneHour());
        var ranges = schedule.DateTimeRanges
                     (
            DateRange.Between
            (
                new DateTime(2021, 10, 2),
                new DateTime(2021, 10, 20)
            )
                     );

        Assert.That
        (
            ranges,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 12, 22, 0, 0),
                new DateTime(2021, 10, 12, 23, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 15, 22, 0, 0),
                new DateTime(2021, 10, 15, 23, 0, 0)
            )
        }
            ),
            "Should be in range when date is on an allowed day of the month"
        );
    }
示例#9
0
 public DateTimeRange Until(DateTimeOffset end) => DateTimeRange.Between(start, end);
示例#10
0
    public void ShouldDeserializeSchedule()
    {
        var schedule = new AggregateSchedule
                       (
            Schedule.On(DayOfWeek.Monday)
            .At(TimeRange.From(10, 0).ForOneHour()),
            Schedule.On(new MonthDay(15))
            .At(TimeRange.From(11, 0).ForOneHour()),
            Schedule.First(DayOfWeek.Monday).OfEveryMonth()
            .At(TimeRange.From(12, 0).ForOneHour()),
            Schedule.On(new YearDay(10, 13))
            .At(TimeRange.From(13, 0).ForOneHour()),
            Schedule.First(DayOfWeek.Tuesday).Of(Months.October)
            .At(TimeRange.From(14, 0).ForOneHour()),
            Schedule.Every(2).Weeks().Starting(new DateTime(2021, 10, 12))
            .At(TimeRange.From(15, 0).ForOneHour())
                       );
        var serialized   = schedule.Serialize();
        var deserialized = AggregateSchedule.Deserialize(serialized);

        Assert.That
        (
            deserialized.DateTimeRanges
            (
                DateRange.Between(new DateTime(2021, 10, 1), new DateTime(2021, 10, 31))
            ),
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 4, 10, 0, 0),
                new DateTime(2021, 10, 4, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 4, 12, 0, 0),
                new DateTime(2021, 10, 4, 13, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 5, 14, 0, 0),
                new DateTime(2021, 10, 5, 15, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 11, 10, 0, 0),
                new DateTime(2021, 10, 11, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 12, 15, 0, 0),
                new DateTime(2021, 10, 12, 16, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 13, 13, 0, 0),
                new DateTime(2021, 10, 13, 14, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 15, 11, 0, 0),
                new DateTime(2021, 10, 15, 12, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 18, 10, 0, 0),
                new DateTime(2021, 10, 18, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 25, 10, 0, 0),
                new DateTime(2021, 10, 25, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 26, 15, 0, 0),
                new DateTime(2021, 10, 26, 16, 0, 0)
            )
        }
            )
        );
    }
示例#11
0
 public bool IsInTimeRange(DateTimeOffset value)
 => DateTimeRange.Between(StartTime(value), EndTime(value)).IsInRange(value);
示例#12
0
 public DateTimeRange Range(DateTimeOffset date)
 => DateTimeRange.Between(StartTime(date), EndTime(date));