Git Product home page Git Product logo

dates.recurring's People

Contributors

gavynriebau avatar joshklingler avatar markedward-bars avatar markybry avatar nikkilocke avatar rars avatar seangwright avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dates.recurring's Issues

Update Humanizer reference to Humanizer.Core

Humanizer updated their repository and released version 2.0 which restructured their project. Humanizer.Core now suffices as a library for your project and doesn't include all of the localization .dlls.

I can make a pull request to update this project to reference the updated Humanizr nuget package if you would be willing to update your Nuget package.

Thanks!

Edit --

Here is my pull request #2

Is this a dead repo?

Are there any plans to continue to develop \accept pull requests on this repository?

Calculation of the last day if it matches the endDate

Hey :)

I just noticed that the calculation of the last day differs for each period when the last day matches the endDate. For the daily/weekly period, the last day is included in the calculation if it is the same as the endDate. However, for the monthly/yearly period, it is not included. Is there a reason for this difference, or is it a bug?

In the following example I used the weekly calculation and the endDate is the 29.01.2024 and the last calculated date (Monday) is also the 29.01.2024. In the second example I used the monthly calculation and the last calculated day also matches the endDate but is not included in the result.

I would expect the endDate to always be included in the result or at least the same behaviour for all periods.
Appreciate your feedback.

// First example
var dates = new List<DateTime>();

var startDate = new DateTime(2024, 1, 1);
var endDate = new DateTime(2024, 1, 29);

var weekly = Recurs
  .Starting(startDate)
  .Every(1)
  .Weeks()
  .OnDay(DayOfWeek.Monday)
  .Ending(endDate)
  .Build();

DateTime? nextDate = DateTime.MinValue;

while (nextDate.HasValue && nextDate <= endDate)
{
  if (nextDate != DateTime.MinValue) dates.Add(nextDate.Value);
  nextDate = weekly.Next(nextDate.Value);
}


// Second example
var dates = new List<DateTime>();

var startDate = new DateTime(2024, 1, 1);
var endDate = new DateTime(2024, 3, 1);

var monthly = Recurs
  .Starting(startDate)
  .Every(1)
  .Months()
  .OnDay(1)
  .Ending(endDate)
  .Build();

DateTime? nextDate = DateTime.MinValue;

while (nextDate.HasValue && nextDate <= endDate)
{
  if (nextDate != DateTime.MinValue) dates.Add(nextDate.Value);
  nextDate = monthly.Next(nextDate.Value);
}

Improvement - Method to return full list of dates between the set up dates

Small suggestion to have a method to retrieve all dates,
Currently I'm doing this, not sure if it's the best

`// Weekly recurrences
var weekly = Recurs
.Starting(request.DateStart.DateTime)
.Every(1)
.Weeks()
.FirstDayOfWeek(DayOfWeek.Monday)
.OnDays(Day.WEDNESDAY) //TODO Move to a options object/model
.Ending(request.DateEnd.DateTime)
.Build();

List dates = new();
DateTime? prevData = request.DateStart;
while ((prevData = weekly.Next(prevData.Value)).HasValue)
{
dates.Add(prevData.Value);
}

return dates;`

Supporting netcoreapp2.0 again

Hi,

At one time this library used multi-targetting to support both .Net standard 2.1 as 2.0
I see that this has been changed so supposedly add support to .Net 5.

I'm no expert on the matter but if I understand correctly there is no reason this codebase can't be compiled against multiple target frameworks.

<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0</TargetFrameworks>

This seems to build just fine.
For the project i'm currently working on we are stuck on .Net 4.7 so targetting netstandard2.0 would mean we could use the lastest version.

Nuget release

Is there any plans to have a new nuget release created from master?

Skip Weekends

First of all, awesome library. I've been asked to implement Outlook-style recurring calendar events into a project and Dates.Recurring can do all of the permutations required except one. We need events to occur every "x" days (which you support) with the option to include or exclude weekends. I started looking at your "Daily.cs" file with the intent of either modifying it or cloning it and creating a "WeekDay.cs" option. Does this sound like a reasonable approach? Or, do you have another suggestion to support the "exclude weekends" feature that I need?

First date of an every saturday schedule returns different date

This test (I made) fails, but should pass I think

    [Fact]
    public void Daily_Every_Saturday_First()
    {
        // Arrange.
        IRecurring daily = Recurs
            .Starting(new DateTime(2019, 1, 16)) //Starting on a wednesday
            .Every(1)
            .Days()
            .Including(Day.SATURDAY) //Only on saturdays
            .Ending(new DateTime(2019, 5, 15))
            .Build();

        // Act.
        List<DateTime> dates = new List<DateTime>();

        DateTime? date = new DateTime(2019, 1, 1); //Date earlier, could be from somewhere else
        while (date.HasValue)
        {
            date = daily.Next(date.Value);
            if (!date.HasValue)
            {
                break;
            }

            dates.Add(date.Value);
        }

        Assert.Equal(new DateTime(2019, 1, 19), dates.First()); //First occurrence in a every saturday schedule should be a saturday
    }

Last Day of every month

Hi,
I'm trying get a recurrence rule like "Last day of every month" but couldn't figure out if it's not supported or I'm missing something.

Can you please confirm if it's possible to include last day of every month in recurrence?

Thanks

Faraz

I am trying to get the Last Monday of every month.

IRecurring rule;
rule = Recurs.Starting(new DateTime(2023,1,1))
.Every(1)
.Months()
.OnOrdinalWeek(Ordinal.LAST).OnDay(DayOfWeek.Monday)
.Ending(new DateTime(2023,6,15))
.Build();
DateTime dt = new DateTime(2023, 1, 1);
while (rule.Next(dt).HasValue)
{
dt = rule.Next(dt).Value;
result.Add(dt);
}
the result was supposed to give me 5 different dates. but every time rule.Next() is executed it returns the same date that is provided as the parameter. ends up as an infinite loop.

Unify behavior

The DaysBuilder has Including() which takes one or more days, The WeekBuilder has OnDays() taking the same parameter. Both are optional. I like to have something like that for the MonthBuilder as well. Since OnDays better conveys the meaning I suggest doing OnDays() there as well so it aligns with the WeeksBuilder.

Apart from that it would be nice to have OnOrdinalWeek() and OnDay() working the same way as Including/OnDays(), so, optional, and making the parameters flags.

I dont know why this is different than days/months because having a 1st & 2nd week of a month does not equal having a 3rd week like the test has now.

So for non-breaking changes I suggest:

  • Add OnDays() to MonthBuilder (optional but accepting flags)
  • Make OnOrdinalWeek() and OnDay() optional (and omitting it would mean all weeks/days)
  • Add OnWeeks() to MonthBuilder (optional but accepting flags)

Then a breaking change would be:

  • Change Include() to OnDays() in the DaysBuilder (Thats just for semantics)
  • Remove OnOrdinalWeek() and OnDay() because that functionality would be covered with the new OnWeeks() and OnDays()

Would you accept a PR for this, and if so is it ok to do the breaking changes?

Feature Request: Allow returning of dates before start date

Currently IRecurring.Previous() will return null if the result would be before the date passed to Starting(); would it be possible to add an option for this restriction to be lifted? My use case is that I need a schedule that is every other Thursday, so I use the start date to indicate which Thursdays should be included, but I'll still need Thursdays that are arbitrarily in the past.

Get a list of dates

I dont know if I'm missing something, but if I want to have a list of dates from a pattern I do this:

        public List<DateTime> DatesRecurringListContains()
        {
            var r = Recurs
                .Starting(new DateTime(2017, 1, 1))
                .Every(2)
                .Days()
                .Ending(new DateTime(2017, 4, 30))
                .Build();

            var f = r.Next(new DateTime(2017, 1, 1).AddDays(-1));
            if (f.HasValue)
            {
                var rl = new List<DateTime> { f.Value };
                while (f != null)
                {
                    f = r.Next(f.Value);
                    if (f != null) rl.Add(f.Value);
                }

                if (r.Next(new DateTime(2017, 4, 28)) == new DateTime(2017, 4, 29))
                {
                    return rl;
                }
            }
            return null;
        }

But this is bad for performance, compared to some alternatives:

Host Process Environment Information:
BenchmarkDotNet.Core=v0.9.9.0
OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i5-4590 CPU 3.30GHz, ProcessorCount=4
Frequency=3215221 ticks, Resolution=311.0206 ns, Timer=TSC
CLR=MS.NET 4.0.30319.42000, Arch=32-bit RELEASE
GC=Concurrent Workstation
JitModules=clrjit-v4.6.1080.0

Type=Benches  Mode=Throughput  
Method Median StdDev
DatesRecurringListContains 159.6398 us 1.2346 us
DarecaliListContains 3.0112 us 0.1232 us

Is there a smarter way to get a list of the recurring dates?

Last Working Day of Month

I was wondering if you have a function for finding the last working day of each month.

I was thinking that using the OnDay with a bitwise expression would work but this does not seem to be returning the correct information

nextPaymentRun = Dates.Recurring.Recurs.Starting(FirstDate) .Every(Interval) .Months() .OnOrdinalWeek(Dates.Recurring.Ordinal.FIRST) .OnDay(DayOfWeek.Monday | DayOfWeek.Tuesday | DayOfWeek.Wednesday | DayOfWeek.Thursday | DayOfWeek.Friday) .Build() .Next(NextDate);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.