<commit_before>if (!recurrence)
    var recurrence = {};


recurrence.Rule = function(freq, options) {
    this.init(freq, options);
};
recurrence.Rule.prototype = {
    init: function(freq, options) {
        this.freq = freq;

        options = options || {};
        this.interval = options.interval || 1;
        this.wkst = options.wkst || null;
        this.count = options.count || null;
        this.until = options.until || null;

        recurrence.array.foreach(
            recurrence.byparams, function (param) {
                if (options[param]) {
                    var value = options[param];
                    if (value == null)
                        value = [];
                    this[param] = recurrence.array.from(value);
                } else {
                    this[param] = [];
                }
            }, this);
    },

    copy: function() {
        var until = this.until;
        if (until)
            until = new Date(until.valueOf());
        var rule = new recurrence.Rule(this.freq, this);
        rule.until = until;
        return rule;
    },

    update: function(rule) {
        rule = rule.copy();
        this.freq = rule.freq;
        this.interval = rule.interval;
        this.wkst = rule.wkst;
        this.until = rule.until;
        this.count = rule.count;

        recurrence.array.foreach(
            recurrence.byparams, function(param) {
                this[param] = rule[param];
            }, this);
    },

    get_display_text: function(short) {
        short = short || false;
        var parts = [];

        var get_position_display = function(position) {
            if (short)
                return recurrence.display.weekdays_position_short[
                    String(position)];
            else
                return recurrence.display.weekdays_position[
                    String(position)];
        };
        var get_weekday_display = function(number) {
            if (short)
                return recurrence.display.weekdays_short[number];
            else
                return recurrence.display.weekdays[number];
        };
        var get_position_weekday = function(rule) {
            var items = [];
            if (rule.bysetpos.length && rule.byday.length) {
                recurrence.array.foreach(
                    rule.bysetpos, function(x) {
                        var label = get_position_display(x || 1);
                        recurrence.array.foreach(
                            rule.byday, function(y) {
                                var weekday_display = get_weekday_display(
                                    recurrence.to_weekday(y).number);
                                items.push(
                                    interpolate(
                                        label, {'weekday': weekday_display}, true));
                            });
                    });

            } else if (rule.byday.length) {
                // TODO byday Weekday objects without index means
                // every weekday in the month, and so should appear in
                // plural. i.e. 'on sundays' instead of
                // 'on the first sunday'.
                recurrence.array.foreach(
                    rule.byday, function(x, i) {
                        var label = get_position_display(x.index || 1);
                        var weekday_display = get_weekday_display(
                            recurrence.to_weekday(x).number);
                        items.push(
                            interpolate(
                                label, {'weekday': weekday_display}, true));
                    });
            }
            return items.join(', ');
        }

        if (this.interval > 1)
            parts.push(
                interpolate(
                    recurrence.display.tokens.every_number_freq, {
                        'number': this.interval,
                        'freq': recurrence.display.timeintervals_plural[this.freq]
                    }, true));
        else
            parts.push(recurrence.display.frequencies[this.freq]);

        if (this.freq == recurrence.YEARLY) {
            if (this.bymonth.length) {
                // i.e. 'each january, june'
                if (short)
                    var months = recurrence.display.months_short;
                else
                    var months = recurrence.display.months;
                var items = recurrence.array.foreach(
                    this.bymonth, function(month, i) {
                        return months[month - 1];
                    });
                items = items.join(', ');
                parts.push(
                    interpolate(
                        recurrence.display.tokens.each,
                        {'items': items}, true));
            }

            if (this.byday.length || this.bysetpos.length) {
                var weekday_items = get_position_weekday(this);
                parts.push(
                    interpolate(
                        recurrence.display.tokens.on_the_items,
                        {'items': weekday_items}, true));
            }
        }

        if (this.freq == recurrence.MONTHLY) {
            if (this.bymonthday.length) {
                // i.e. 'on the 1st, 5th, 10th'
                var items = recurrence.array.foreach(
                    this.bymonthday, function(day, i) {
                        var dt = new Date();
                        dt.setDate(day);
                        return recurrence.date.format(dt, '%j%S');
                });
                items = items.join(', ');
                parts.push(
                    interpolate(
                        recurrence.display.tokens.on_the_items,
                        {'items': items}, true));

            } else if (this.byday.length) {
                if (this.byday.length || this.bysetpos.length) {
                    var weekday_items = get_position_weekday(this);
                    parts.push(
                        interpolate(<commit_msg>bug: when current month has less than 31 days in monthly recurring<commit_after>if (!recurrence)
    var recurrence = {};


recurrence.Rule = function(freq, options) {
    this.init(freq, options);
};
recurrence.Rule.prototype = {
    init: function(freq, options) {
        this.freq = freq;

        options = options || {};
        this.interval = options.interval || 1;
        this.wkst = options.wkst || null;
        this.count = options.count || null;
        this.until = options.until || null;

        recurrence.array.foreach(
            recurrence.byparams, function (param) {
                if (options[param]) {
                    var value = options[param];
                    if (value == null)
                        value = [];
                    this[param] = recurrence.array.from(value);
                } else {
                    this[param] = [];
                }
            }, this);
    },

    copy: function() {
        var until = this.until;
        if (until)
            until = new Date(until.valueOf());
        var rule = new recurrence.Rule(this.freq, this);
        rule.until = until;
        return rule;
    },

    update: function(rule) {
        rule = rule.copy();
        this.freq = rule.freq;
        this.interval = rule.interval;
        this.wkst = rule.wkst;
        this.until = rule.until;
        this.count = rule.count;

        recurrence.array.foreach(
            recurrence.byparams, function(param) {
                this[param] = rule[param];
            }, this);
    },

    get_display_text: function(short) {
        short = short || false;
        var parts = [];

        var get_position_display = function(position) {
            if (short)
                return recurrence.display.weekdays_position_short[
                    String(position)];
            else
                return recurrence.display.weekdays_position[
                    String(position)];
        };
        var get_weekday_display = function(number) {
            if (short)
                return recurrence.display.weekdays_short[number];
            else
                return recurrence.display.weekdays[number];
        };
        var get_position_weekday = function(rule) {
            var items = [];
            if (rule.bysetpos.length && rule.byday.length) {
                recurrence.array.foreach(
                    rule.bysetpos, function(x) {
                        var label = get_position_display(x || 1);
                        recurrence.array.foreach(
                            rule.byday, function(y) {
                                var weekday_display = get_weekday_display(
                                    recurrence.to_weekday(y).number);
                                items.push(
                                    interpolate(
                                        label, {'weekday': weekday_display}, true));
                            });
                    });

            } else if (rule.byday.length) {
                // TODO byday Weekday objects without index means
                // every weekday in the month, and so should appear in
                // plural. i.e. 'on sundays' instead of
                // 'on the first sunday'.
                recurrence.array.foreach(
                    rule.byday, function(x, i) {
                        var label = get_position_display(x.index || 1);
                        var weekday_display = get_weekday_display(
                            recurrence.to_weekday(x).number);
                        items.push(
                            interpolate(
                                label, {'weekday': weekday_display}, true));
                    });
            }
            return items.join(', ');
        }

        if (this.interval > 1)
            parts.push(
                interpolate(
                    recurrence.display.tokens.every_number_freq, {
                        'number': this.interval,
                        'freq': recurrence.display.timeintervals_plural[this.freq]
                    }, true));
        else
            parts.push(recurrence.display.frequencies[this.freq]);

        if (this.freq == recurrence.YEARLY) {
            if (this.bymonth.length) {
                // i.e. 'each january, june'
                if (short)
                    var months = recurrence.display.months_short;
                else
                    var months = recurrence.display.months;
                var items = recurrence.array.foreach(
                    this.bymonth, function(month, i) {
                        return months[month - 1];
                    });
                items = items.join(', ');
                parts.push(
                    interpolate(
                        recurrence.display.tokens.each,
                        {'items': items}, true));
            }

            if (this.byday.length || this.bysetpos.length) {
                var weekday_items = get_position_weekday(this);
                parts.push(
                    interpolate(
                        recurrence.display.tokens.on_the_items,
                        {'items': weekday_items}, true));
            }
        }

        if (this.freq == recurrence.MONTHLY) {
            if (this.bymonthday.length) {
                // i.e. 'on the 1st, 5th, 10th'
                var items = recurrence.array.foreach(
                    this.bymonthday, function(day, i) {
                        var dt = new Date();
                        dt.setMonth(0);
                        dt.setDate(day);
                        return recurrence.date.format(dt, '%j%S');
                });
                items = items.join(', ');
                parts.push(
                    interpolate(
                        recurrence.display.tokens.on_the_items,
                        {'items': items}, true));

            } else if (this.byday.length) {
                if (this.byday.length || this.bysetpos.length) {
                    var weekday_items = get_position_weekday(this);
                    parts.push(
                        interpolate(
{'fraction_non_alphanumeric': 0.1019939279560187, 'fraction_numerical': 0.0017231476163124641, 'mean_word_length': 1.146530468474815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4323651', 'n_tokens_mistral': 3188, 'n_tokens_neox': 2964, 'n_words': 605}