<commit_before>﻿namespace CronGadgetry
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public class CronExpression
    {
        private const char ExpressionSeperator = ' ';
        private const string AllToken = "*";
        private const string AnyToken = "?";
        private const string IncrementsSeperator = "/";
        private const string RangeChar = "-";
        private const string LastChar = "L";
        private const string WeekdayChar = "W";
        private const string LastWeekdayToken = "LW";
        private const string OccurrenceSeperator = "#";

        private readonly IRange _nanoseconds;
        private readonly IRange _microseconds;
        private readonly IRange _milliseconds;
        private readonly IRange _seconds;
        private readonly IRange _minutes;
        private readonly IRange _hours;
        private readonly IDayRange _days;
        private readonly IRange _months;
        private readonly IRange _years;
        private readonly TimeSpan _offset;

        public CronExpression(IRange nanosecons, IRange microseconds, IRange milliseconds, IRange seconds, IRange minutes, IRange hours, IDayRange daysOfMonth, IRange months, IDayRange daysOfWeek)
            : this(nanosecons, microseconds, milliseconds, seconds, minutes, hours, daysOfMonth, months, daysOfWeek, null, TimeSpan.Zero)
        {
        }

        public CronExpression(IRange nanoseconds, IRange microseconds, IRange milliseconds, IRange seconds, IRange minutes, IRange hours, IDayRange daysOfMonth, IRange months, IDayRange daysOfWeek, TimeSpan offset)
            : this(nanoseconds, microseconds, milliseconds, seconds, minutes, hours, daysOfMonth, months, daysOfWeek, null, offset)
        {
        }

        public CronExpression(IRange nanoseconds, IRange microseconds, IRange milliseconds, IRange seconds, IRange minutes, IRange hours, IDayRange daysOfMonth, IRange months, IDayRange daysOfWeek, IRange years)
            : this(nanoseconds, microseconds, milliseconds, seconds, minutes, hours, daysOfMonth, months, daysOfWeek, years, TimeSpan.Zero)
        {
        }

        public CronExpression(IRange nanoseconds, IRange microseconds, IRange milliseconds, IRange seconds, IRange minutes, IRange hours, IDayRange daysOfMonth, IRange months, IDayRange daysOfWeek, IRange years, TimeSpan offset)
        {
            if (daysOfMonth != null && daysOfWeek != null)
            {
                throw new NotSupportedException();
            }

            _nanoseconds = nanoseconds;
            _microseconds = microseconds;
            _milliseconds = milliseconds;
            _seconds = seconds;
            _minutes = minutes;
            _hours = hours;
            _days = daysOfMonth ?? daysOfWeek;
            _months = months;
            _years = years;
            _offset = offset;
        }
        
        public bool HasTime(DateTimeOffset value)
        {
            DateTimeOffset temp = value.ToOffset(_offset);

            return
                (_years == null || _years.Contains(temp.Year)) &&
                _months.Contains(temp.Month) &&
                _days.Contains(temp.Day, temp.Month, temp.Year) &&
                _hours.Contains(temp.Hour) &&
                _minutes.Contains(temp.Minute) &&
                _seconds.Contains(temp.Second) &&
                _milliseconds.Contains(temp.Millisecond) &&
                _microseconds.Contains(temp.GetMicroseconds()) &&
                _nanoseconds.Contains(temp.GetNanoseconds());
        }

        public DateTimeOffset? GetTimeAfter(DateTimeOffset value)
        {
            IEnumerable<DateTimeOffset> times = GetAllTimesAfter(value);

            foreach (var time in times)
            {
                return time;
            }

            return null;
        }

        public IEnumerable<DateTimeOffset> GetAllTimesAfter(DateTimeOffset value)
        {
            DateTimeOffset temp = value.ToOffset(_offset);

            bool firstYear = true;
            bool firstMonth = true;
            bool firstDay = true;
            bool firstHour = true;
            bool firstMinute = true;
            bool firstSecond = true;
            bool firstMillisecond = true;
            bool firstMicrosecond = true;

            var years = _years != null ? _years.GetViewFrom(temp.Year).Values : Enumerable.Range(temp.Year, DateTimeOffset.MaxValue.Year);

            foreach (var year in years)
            {
                firstYear &= year == value.Year;

                foreach (var month in firstYear ? _months.GetViewFrom(temp.Month).Values : _months.Values)
                {
                    firstMonth &= firstYear && month == value.Month;

                    foreach (var day in firstMonth ? _days.GetViewFrom(temp.Year, temp.Month, temp.Day).Values : _days.GetValues(year, month))
                    {
                        firstDay &= firstMonth && day == value.Day;

                        foreach (var hour in firstDay ? _hours.GetViewFrom(temp.Hour).Values : _hours.Values)
                        {
                            firstHour &= firstDay && hour == value.Hour;

                            foreach (var minute in firstHour ? _minutes.GetViewFrom(temp.Minute).Values : _minutes.Values)
                            {
                                firstMinute &= firstHour && minute == value.Minute;

                                foreach (var second in firstMinute ? _seconds.GetViewFrom(temp.Second).Values : _seconds.Values)
                                {
                                    firstSecond &= firstMinute && second == value.Second;<commit_msg>Bug fix<commit_after>﻿namespace CronGadgetry
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public class CronExpression
    {
        private const char ExpressionSeperator = ' ';
        private const string AllToken = "*";
        private const string AnyToken = "?";
        private const string IncrementsSeperator = "/";
        private const string RangeChar = "-";
        private const string LastChar = "L";
        private const string WeekdayChar = "W";
        private const string LastWeekdayToken = "LW";
        private const string OccurrenceSeperator = "#";

        private readonly IRange _nanoseconds;
        private readonly IRange _microseconds;
        private readonly IRange _milliseconds;
        private readonly IRange _seconds;
        private readonly IRange _minutes;
        private readonly IRange _hours;
        private readonly IDayRange _days;
        private readonly IRange _months;
        private readonly IRange _years;
        private readonly TimeSpan _offset;

        public CronExpression(IRange nanosecons, IRange microseconds, IRange milliseconds, IRange seconds, IRange minutes, IRange hours, IDayRange daysOfMonth, IRange months, IDayRange daysOfWeek)
            : this(nanosecons, microseconds, milliseconds, seconds, minutes, hours, daysOfMonth, months, daysOfWeek, null, TimeSpan.Zero)
        {
        }

        public CronExpression(IRange nanoseconds, IRange microseconds, IRange milliseconds, IRange seconds, IRange minutes, IRange hours, IDayRange daysOfMonth, IRange months, IDayRange daysOfWeek, TimeSpan offset)
            : this(nanoseconds, microseconds, milliseconds, seconds, minutes, hours, daysOfMonth, months, daysOfWeek, null, offset)
        {
        }

        public CronExpression(IRange nanoseconds, IRange microseconds, IRange milliseconds, IRange seconds, IRange minutes, IRange hours, IDayRange daysOfMonth, IRange months, IDayRange daysOfWeek, IRange years)
            : this(nanoseconds, microseconds, milliseconds, seconds, minutes, hours, daysOfMonth, months, daysOfWeek, years, TimeSpan.Zero)
        {
        }

        public CronExpression(IRange nanoseconds, IRange microseconds, IRange milliseconds, IRange seconds, IRange minutes, IRange hours, IDayRange daysOfMonth, IRange months, IDayRange daysOfWeek, IRange years, TimeSpan offset)
        {
            if (daysOfMonth != null && daysOfWeek != null)
            {
                throw new NotSupportedException();
            }

            _nanoseconds = nanoseconds;
            _microseconds = microseconds;
            _milliseconds = milliseconds;
            _seconds = seconds;
            _minutes = minutes;
            _hours = hours;
            _days = daysOfMonth ?? daysOfWeek;
            _months = months;
            _years = years;
            _offset = offset;
        }
        
        public bool HasTime(DateTimeOffset value)
        {
            DateTimeOffset temp = value.ToOffset(_offset);

            return
                (_years == null || _years.Contains(temp.Year)) &&
                _months.Contains(temp.Month) &&
                _days.Contains(temp.Day, temp.Month, temp.Year) &&
                _hours.Contains(temp.Hour) &&
                _minutes.Contains(temp.Minute) &&
                _seconds.Contains(temp.Second) &&
                _milliseconds.Contains(temp.Millisecond) &&
                _microseconds.Contains(temp.GetMicroseconds()) &&
                _nanoseconds.Contains(temp.GetNanoseconds());
        }

        public DateTimeOffset? GetTimeAfter(DateTimeOffset value)
        {
            IEnumerable<DateTimeOffset> times = GetAllTimesAfter(value);

            foreach (var time in times)
            {
                return time;
            }

            return null;
        }

        public IEnumerable<DateTimeOffset> GetAllTimesAfter(DateTimeOffset value)
        {
            DateTimeOffset temp = value.ToOffset(_offset);

            bool firstYear = true;
            bool firstMonth = true;
            bool firstDay = true;
            bool firstHour = true;
            bool firstMinute = true;
            bool firstSecond = true;
            bool firstMillisecond = true;
            bool firstMicrosecond = true;

            var years = _years != null ? _years.GetViewFrom(temp.Year).Values : Enumerable.Range(temp.Year, DateTimeOffset.MaxValue.Year - temp.Year + 1);

            foreach (var year in years)
            {
                firstYear &= year == value.Year;

                foreach (var month in firstYear ? _months.GetViewFrom(temp.Month).Values : _months.Values)
                {
                    firstMonth &= firstYear && month == value.Month;

                    foreach (var day in firstMonth ? _days.GetViewFrom(temp.Year, temp.Month, temp.Day).Values : _days.GetValues(year, month))
                    {
                        firstDay &= firstMonth && day == value.Day;

                        foreach (var hour in firstDay ? _hours.GetViewFrom(temp.Hour).Values : _hours.Values)
                        {
                            firstHour &= firstDay && hour == value.Hour;

                            foreach (var minute in firstHour ? _minutes.GetViewFrom(temp.Minute).Values : _minutes.Values)
                            {
                                firstMinute &= firstHour && minute == value.Minute;

                                foreach (var second in firstMinute ? _seconds.GetViewFrom(temp.Second).Values : _seconds.Values)
                                {
                                    firstSecond &= firstMinute && second == value.Second;
{'fraction_non_alphanumeric': 0.07762114537444934, 'fraction_numerical': 8.81057268722467e-05, 'mean_word_length': 1.976140534871526, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1408520', 'n_tokens_mistral': 2928, 'n_tokens_neox': 2734, 'n_words': 756}