<commit_before>import math
import datetime


class Holidays(object):

    rules = []

    MONTH_LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    def _day_rule_matches(self, rule, dt):
        return dt.month == rule.get("month") and dt.day == rule.get("day")

    def _weekday_rule_matches(self, rule, dt):
        if dt.month == rule.get("month") and dt.weekday() == rule.get("weekday"):
            # Check for +week specification
            if math.floor((dt.day - 1) / 7) == rule.get("week") - 1:
                return True
            # Check for -week specification
            length = self.MONTH_LENGTHS[dt.month]
            if math.floor((length - dt.day) / 7) + 1 == rule.get("week") * -1:
                return True
        return False

    def isholiday(self, dt):
        for r in self.rules:
            if self._day_rule_matches(r, dt) or self._weekday_rule_matches(r, dt):
                return True
        return False

    def __call__(self, curr, end=None):
        while end is None or curr < end:
            if self.isholiday(curr):
                yield curr
            curr = curr + datetime.timedelta(days=1)<commit_msg>addressed issue with leap years<commit_after>import math
import datetime
import calendar


class Holidays(object):

    rules = []

    def month_length(self, year,month):
        return calendar.monthrange(year,month)[1]

    def _day_rule_matches(self, rule, dt):
        return dt.month == rule.get("month") and dt.day == rule.get("day")

    def _weekday_rule_matches(self, rule, dt):
        if dt.month == rule.get("month") and dt.weekday() == rule.get("weekday"):
            # Check for +week specification
            if math.floor((dt.day - 1) / 7) == rule.get("week") - 1:
                return True
            # Check for -week specification
            length = self.month_length(dt.year,dt.month)
            if math.floor((length - dt.day) / 7) + 1 == rule.get("week") * -1:
                return True
        return False

    def isholiday(self, dt):
        for r in self.rules:
            if self._day_rule_matches(r, dt) or self._weekday_rule_matches(r, dt):
                return True
        return False

    def __call__(self, curr, end=None):
        while end is None or curr < end:
            if self.isholiday(curr):
                yield curr
            curr = curr + datetime.timedelta(days=1)
{'fraction_non_alphanumeric': 0.1213511259382819, 'fraction_numerical': 0.01626355296080067, 'mean_word_length': 2.0214105793450883, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6323681', 'n_tokens_mistral': 774, 'n_tokens_neox': 723, 'n_words': 205}