开发者

is there a formula to calculate recurrence

开发者 https://www.devze.com 2023-01-11 13:54 出处:网络
I\'m using ASP.Net MVC2. I would like to know if there is there a formula to calculate recurre开发者_StackOverflownce date? So from my client side I\'m selecting dates and using ajax.post to send to t

I'm using ASP.Net MVC2. I would like to know if there is there a formula to calculate recurre开发者_StackOverflownce date? So from my client side I'm selecting dates and using ajax.post to send to the controller. My expecting result would be like so for example:

maxdate is September 30th currentdate is today duration is 3 days for every week

so output would be aug12-aug14 aug19-aug21 aug26-28 until the end of september


Enumerable.Range(0, int.MaxValue)
    .Select(i => new
                    {
                        start = DateTime.Today.AddDays(7*i), 
                        end = DateTime.Today.AddDays(7*i + 2)
                    })
    .TakeWhile(d => d.end <= new DateTime(2010, 9, 30))

Unless you're looking for the dates in between start and end inclusive:

Enumerable.Range(0, int.MaxValue)
    .SelectMany(i => new[]
                        {
                            DateTime.Today.AddDays(7*i),
                            DateTime.Today.AddDays(7*i + 1),
                            DateTime.Today.AddDays(7*i + 2)
                        })
    .TakeWhile(d => d <= new DateTime(2010, 9, 30))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号