Add support for cron range and list patterns#18
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesRange and List Pattern Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR expands CronHelper.ToHumanReadable to generate clearer descriptions for cron expressions that use numeric ranges (e.g. 1-5) and comma-separated lists (e.g. 1,3,5), and adds unit tests covering the new scenarios.
Changes:
- Added helper logic to describe day-of-week ranges/lists and day-of-month ordinals for ranges/lists.
- Added time-pattern handling for hour/minute ranges and explicit time lists (e.g.
8,12,17). - Added MSTest coverage for day-of-week ranges, hour lists/ranges, minute lists/ranges, and day-of-month ranges/lists.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| CronCraft/Extensions/CronHelper.cs | Adds range/list parsing and description helpers for time fields and day fields. |
| CronCraft.Test/CronHelperTest.cs | Adds unit tests validating the new range/list description outputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (dayOfMonth.Contains('-') && (dayOfWeek == "*" || dayOfWeek == "?")) | ||
| { | ||
| var dayRange = DescribeOrdinals(dayOfMonth); | ||
| return $"Every day from the {dayRange} {Phrase("AtTime", time)}"; | ||
| } |
| if (minute.Contains('-') && int.TryParse(hour, out var fixedHour)) | ||
| { | ||
| var bounds = minute.Split('-', StringSplitOptions.TrimEntries); | ||
| if (bounds.Length == 2 && | ||
| int.TryParse(bounds[0], out var startMinute) && | ||
| int.TryParse(bounds[1], out var endMinute)) | ||
| { | ||
| description = | ||
| $"Every minute from {FormatTime(fixedHour, startMinute, timeZone)} to {FormatTime(fixedHour, endMinute, timeZone)}"; | ||
| return true; | ||
| } | ||
| } |
| if ((hour.Contains(',') || minute.Contains(',')) && | ||
| TryExpandValues(hour, out var hours) && | ||
| TryExpandValues(minute, out var minutes)) | ||
| { | ||
| var times = ( | ||
| from parsedHour in hours | ||
| from parsedMinute in minutes | ||
| select FormatTime(parsedHour, parsedMinute, timeZone)) | ||
| .ToList(); | ||
|
|
||
| description = $"At {JoinDescriptions(times)}"; | ||
| return true; | ||
| } | ||
|
|
|
🎉 Thank you for your contribution! This PR was included in CronCraft v1.0.5 and is now live on NuGet for everyone to use. We really appreciate the time and effort you put in — it makes the library better for the whole community! 🚀 |
|
🎉 Thank you for your contribution! This PR was included in CronCraft v1.0.6 and is now live on NuGet for everyone to use. We really appreciate the time and effort you put in — it makes the library better for the whole community! 🚀 |
Summary
1-5,7L,W, and#handlingWhy
CronCraft previously handled only a subset of comma-separated day expressions and did not produce useful descriptions for common range patterns such as
1-5or8-17.This change produces human-readable descriptions for schedules including weekday ranges, time ranges, day-of-month ranges, and value lists.
Closes #5
Validation
dotnet test CronCraft.Test/CronCraft.Test.csproj --no-restore— 36 tests passeddotnet build CronCraft.sln --no-restore— succeeded with 0 warnings and 0 errorsSummary by CodeRabbit
Improvements
Tests