Runtime: Add a DateTime method to return all a list of all datetimes within a range.

Created on 8 Jun 2019  路  5Comments  路  Source: dotnet/runtime

Add a DateTime method to return all a list of all datetimes within a range. The method could take in start and end date, and the period for the range.

area-System.Runtime

Most helpful comment

Do I understand it correctly that what you want is basically:

c# static IEnumerable<DateTime> Range(DateTime start, DateTime end, TimeSpan period) { for (DateTime current = start; current <= end; current += period) yield return current; }

To me something like that appears to be too simple and not useful often enough to be worth adding to .Net.

All 5 comments

Do I understand it correctly that what you want is basically:

c# static IEnumerable<DateTime> Range(DateTime start, DateTime end, TimeSpan period) { for (DateTime current = start; current <= end; current += period) yield return current; }

To me something like that appears to be too simple and not useful often enough to be worth adding to .Net.

Aside from @svick's comment:

@prkhandelwal see API Review Process for adding a formal proposal.

Side note: @svick 's implementation may produce surprising results if DateTimeKind is Local, because it won't account for DST changes.
A mismatch in DateTimeKind between start and end may also produce surprising results, particularly if one of them is Unknown.

You would be better off using DateTimeOffset (or switching to NodaTime).

In addition to @svick's recommendation, I've had good results using ncrontab for more advanced needs.

@scalablecory - from the look of that library, it'll fall into (at least some of) the same issues as the earlier recommendation wrt DST.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

noahfalk picture noahfalk  路  3Comments

EgorBo picture EgorBo  路  3Comments

matty-hall picture matty-hall  路  3Comments

omajid picture omajid  路  3Comments

GitAntoinee picture GitAntoinee  路  3Comments