DEV Community

cdilorenzo
cdilorenzo

Posted on

1 1 1

Stop parsing “last 3 business days” by hand — I built a fluent date range parser for .NET

How many times have you written code like this? 👇


csharp
var today = DateTime.Today;
var start = today.AddDays(-7);

while (start.DayOfWeek == DayOfWeek.Saturday || start.DayOfWeek == DayOfWeek.Sunday)
    start = start.AddDays(-1);

Just to figure out what “last 3 business days” means? I got tired of it, so I built this:

var range = SmartDateRange.Parse("last 3 business days");

Console.WriteLine(range.Start); // e.g. 2024-05-29
Console.WriteLine(range.End);   // e.g. 2024-05-31

✅ Supports:

"today", "yesterday"

"last N days"

"last N business days"

"this week", "this month"

And more, with TryParse support for safe usage



---

🔍 Why I Built It

I was working on a reporting dashboard and found that:

Existing libraries were either too heavy (NLP, ML-based)

Or too manual (lots of repetitive date math)


So I built something focused, lightweight, and fluent — no external dependencies, just solid .NET 9.


---

🚀 Features

✅ Fluent API: SmartDateRange.Parse("this week")

✅ TryParse() fallback to avoid exceptions

✅ Easy to integrate into LINQ filters or APIs

✅ Culture-ready (localization support incoming)



---

🧪 Try It

You can grab the package from GitHub:

📦 GitHub: https://github.com/cdilorenzo/SmartDateRangeParser
(Coming soon to NuGet!)


---

🤝 Contribute or Give Feedback

Pull requests welcome

Feature requests encouraged

⭐ Stars appreciated if you find it useful


Let me know what use case you'd like to see supported next!


---

🧠 Built with ❤️ by @cdilorenzo

---
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.