@@ -5,40 +5,31 @@ namespace TickerQ.SourceGenerator.Validation
55{
66 public static class CronValidator
77 {
8- // Format with seconds (6 parts): seconds, minutes, hours, day, month, day-of-week
9- private static readonly int [ ] MinValuesArray6Part = { 0 , 0 , 0 , 1 , 1 , 0 } ;
10- private static readonly int [ ] MaxValuesArray6Part = { 59 , 59 , 23 , 31 , 12 , 6 } ;
11-
12- // Format without seconds (5 parts): minutes, hours, day, month, day-of-week
13- private static readonly int [ ] MinValuesArray5Part = { 0 , 0 , 1 , 1 , 0 } ;
14- private static readonly int [ ] MaxValuesArray5Part = { 59 , 23 , 31 , 12 , 6 } ;
8+ // Format with seconds (6 parts only): seconds, minutes, hours, day, month, day-of-week
9+ private static readonly int [ ] MinValues = { 0 , 0 , 0 , 1 , 1 , 0 } ;
10+ private static readonly int [ ] MaxValues = { 59 , 59 , 23 , 31 , 12 , 6 } ;
1511
1612 // Performance constants
17- private const int MaxPartsCount = 6 ;
13+ private const int RequiredPartsCount = 6 ;
1814
1915 public static bool IsValidCronExpression ( string expression )
2016 {
2117 if ( string . IsNullOrEmpty ( expression ) ) return false ;
2218
2319 // Use Span for efficient string splitting without allocations
2420 var expressionSpan = expression . AsSpan ( ) ;
25- var parts = new string [ MaxPartsCount ] ;
21+ var parts = new string [ RequiredPartsCount ] ;
2622 var partCount = SplitIntoSpan ( expressionSpan , parts ) ;
2723
28- // Support both 5 -part (without seconds) and 6-part ( with seconds) cron expressions
29- if ( partCount != 5 && partCount != 6 )
24+ // Only support 6 -part cron expressions with seconds
25+ if ( partCount != RequiredPartsCount )
3026 return false ;
3127
32- // Select appropriate min/max values based on part count
33- ReadOnlySpan < int > minSpan = partCount == 6
34- ? MinValuesArray6Part
35- : MinValuesArray5Part ;
36-
37- ReadOnlySpan < int > maxSpan = partCount == 6
38- ? MaxValuesArray6Part
39- : MaxValuesArray5Part ;
28+ // Validate each part with corresponding min/max values
29+ ReadOnlySpan < int > minSpan = MinValues ;
30+ ReadOnlySpan < int > maxSpan = MaxValues ;
4031
41- for ( int i = 0 ; i < partCount ; i ++ )
32+ for ( int i = 0 ; i < RequiredPartsCount ; i ++ )
4233 {
4334 if ( ! ValidatePart ( parts [ i ] , minSpan [ i ] , maxSpan [ i ] ) )
4435 return false ;
0 commit comments