Skip to content

Add support for cron range and list patterns#18

Merged
teesofttech merged 1 commit into
masterfrom
feat/issue-5-range-list-patterns
Jun 18, 2026
Merged

Add support for cron range and list patterns#18
teesofttech merged 1 commit into
masterfrom
feat/issue-5-range-list-patterns

Conversation

@teesofttech

@teesofttech teesofttech commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • add range syntax support for day-of-week, hour, minute, and day-of-month fields
  • add comma-separated list support across those cron fields
  • support combined range and list expressions such as 1-5,7
  • preserve existing Quartz L, W, and # handling
  • add unit coverage for range and list scenarios

Why

CronCraft previously handled only a subset of comma-separated day expressions and did not produce useful descriptions for common range patterns such as 1-5 or 8-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 passed
  • dotnet build CronCraft.sln --no-restore — succeeded with 0 warnings and 0 errors

Summary by CodeRabbit

  • Improvements

    • Cron expression descriptions are now more detailed and accurate. Better support for complex patterns including ranges and lists across multiple time fields (day-of-week, hour, minute, day-of-month).
  • Tests

    • Added extensive test coverage for cron formatting with various combinations of ranges, lists, and field configurations.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aecbc96c-79c4-4e36-b961-161e1ac688ff

📥 Commits

Reviewing files that changed from the base of the PR and between 4610fbe and c445470.

📒 Files selected for processing (2)
  • CronCraft.Test/CronHelperTest.cs
  • CronCraft/Extensions/CronHelper.cs

📝 Walkthrough

Walkthrough

CronHelper.BuildHumanReadable is extended to handle range (x-y) and list (,) patterns across day-of-week, hour, minute, and day-of-month cron fields. New private helpers TryDescribeTimePattern, DescribeOrdinals, ExpandDayValues, and a refactored FormatTime overload power this. Eight new unit tests cover each field variant.

Changes

Range and List Pattern Support

Layer / File(s) Summary
Low-level helpers: FormatTime overload, DescribeOrdinals, TryDescribeTimePattern, day-of-week composition
CronCraft/Extensions/CronHelper.cs
FormatTime is split into string and integer overloads. DescribeOrdinals is added for ordinal range/list formatting. TryDescribeTimePattern/TryExpandValues recognize hour/minute range and comma-list expressions. IsAllDays, JoinDays, DescribeDayPart, ExpandDayValues, and JoinDescriptions are reworked to support range phrasing and normalized day-set comparison.
BuildHumanReadable: range/list branches and DescribeOrdinals wiring
CronCraft/Extensions/CronHelper.cs
A new "Range and list patterns" section calls TryDescribeTimePattern and wires JoinDays/DescribeOrdinals for composite descriptions. Existing standard-pattern fallbacks switch from Ordinal to DescribeOrdinals for day-of-month. A new branch handles dayOfMonth range expressions when dayOfWeek is wildcard.
Unit tests for all new range/list field patterns
CronCraft.Test/CronHelperTest.cs
Eight [TestMethod] cases covering day-of-week ranges and range+list, hour ranges on weekdays, explicit hour lists, minute ranges and lists, and day-of-month ranges and lists, each asserting exact human-readable output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • #5: Add support for range (1-5) and list (1,3,5) patterns in all cron fields — This PR directly implements all acceptance criteria from that issue: range syntax in day-of-week, hour, minute, and day-of-month fields; combined range+list patterns (1-5,7); and unit tests covering all scenarios.

Possibly related PRs

  • teesofttech/CronCraft#15: Both PRs modify FormatTime in CronHelper.cs; this PR refactors it into integer/string overloads while PR #15 adjusted it for consistent AM/PM formatting via InvariantCulture.

Poem

🐰 Hop, hop, through the cron fields I go,
Ranges like 1-5 now put on a show,
Lists with commas, days in a row,
"Monday through Friday" — ordinals glow!
No more wildcards left in the unknown,
Every field described, every pattern known. 🌸

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/issue-5-range-list-patterns

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@teesofttech
teesofttech marked this pull request as ready for review June 18, 2026 03:27
Copilot AI review requested due to automatic review settings June 18, 2026 03:27
@teesofttech
teesofttech merged commit ac107bd into master Jun 18, 2026
4 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +149 to +153
if (dayOfMonth.Contains('-') && (dayOfWeek == "*" || dayOfWeek == "?"))
{
var dayRange = DescribeOrdinals(dayOfMonth);
return $"Every day from the {dayRange} {Phrase("AtTime", time)}";
}
Comment on lines +301 to +312
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;
}
}
Comment on lines +314 to +327
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;
}

@teesofttech teesofttech changed the title [codex] Add support for cron range and list patterns Add support for cron range and list patterns Jun 18, 2026
@github-actions

Copy link
Copy Markdown

🎉 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! 🚀

dotnet add package CronCraft --version 1.0.5

@github-actions

Copy link
Copy Markdown

🎉 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! 🚀

dotnet add package CronCraft --version 1.0.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for range (1-5) and list (1,3,5) patterns in all cron fields

2 participants