Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple day of week specifiers #41

Open
darkeagle76 opened this issue Aug 26, 2021 · 1 comment
Open

Support for multiple day of week specifiers #41

darkeagle76 opened this issue Aug 26, 2021 · 1 comment

Comments

@darkeagle76
Copy link

Hi,
I would like to ask if there is a plan to support multple day of week specifiers.
For example this cron expression is currenlty not supported:
0 0 11 ? 8/2 SAT,SUN#3
It means: "At 11:00 AM, on the third Saturday and Sunday of the month, every 2 months, August through December" and allow to apply the "#" specifier to two days of week Saturday and Sunday.
Thanks, regards,
D

@olegbsspb
Copy link

olegbsspb commented Oct 26, 2022

To support extensions L and # in days of the week for range and list, I made a branch and changed only one function:

#if !NET40
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
        private static unsafe long ParseDayOfWeek(ref char* pointer, ref CronExpressionFlag flags, ref byte nthWeekDay)
        {
            var field = CronField.DaysOfWeek;
            if (Accept(ref pointer, '*') || Accept(ref pointer, '?')) return ParseStar(field, ref pointer);

            var dayOfWeek = ParseValue(field, ref pointer);

#if false // Original
            if (AcceptCharacter(ref pointer, 'L')) return ParseLastWeekDay(dayOfWeek, ref flags);
            if (Accept(ref pointer, '#')) return ParseNthWeekDay(field, ref pointer, dayOfWeek, ref flags, out nthWeekDay);

            var bits = ParseRange(field, ref pointer, dayOfWeek, ref flags);
            if (Accept(ref pointer, ',')) bits |= ParseList(field, ref pointer, ref flags);

            return bits;
#else

            var bits = ParseRange(field, ref pointer, dayOfWeek, ref flags);
            if (Accept(ref pointer, ',')) bits |= ParseList(field, ref pointer, ref flags);

            if (AcceptCharacter(ref pointer, 'L'))
                ParseLastWeekDay(dayOfWeek, ref flags);
            else if (Accept(ref pointer, '#')) 
                ParseNthWeekDay(field, ref pointer, dayOfWeek, ref flags, out nthWeekDay);

            return bits;
#endif
        }

Generation works amazingly :)
Examples:
0 10 * * 1-5L
0 10 * * 1-2,5-6#3

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

No branches or pull requests

2 participants