<commit_before><?php
namespace Concrete\Core\Foundation\Repetition;

/**
 * Abstract repetition class
 * This class is used to define and match against various time windows
 *
 * @package Concrete\Core\Foundation\Repetition
 */
abstract class AbstractRepetition implements RepetitionInterface
{

    /**
     * @var string Date string of the start date/time
     */
    protected $startDate;

    /**
     * @var string Date string of the end date/time
     */
    protected $endDate;

    /**
     * @var bool Does the startDate include a time or should we just use the entire day?
     */
    protected $startDateAllDay;

    /**
     * @var bool Does the endDate include a time, or should we just use the entire day?
     */
    protected $endDateAllDay;

    /**
     * @var int self::REPEAT_* enum [ ::REPEAT_DAILY | ::REPEAT_WEEKLY | ::REPEAT_MONTHLY ]
     */
    protected $repeatPeriod;

    /**
     * @var int[] List of numeric representations of the day of the week 0 for sunday, 6 for saturday.
     */
    protected $repeatPeriodWeekDays;

    /**
     * @var int Number for the `repeatPeriod`
     */
    protected $repeatEveryNum;

    /**
     * @var int self::MONTHLY_REPEAT_* enum [ ::MONTHLY_REPEAT_WEEKLY | ::MONTHLY_REPEAT_MONTHLY | ::MONTHLY_REPEAT_LAST_WEEKDAY ]
     */
    protected $repeatMonthBy;

    /**
     * @var int The week day number
     */
    protected $repeatMonthLastWeekday;

    /**
     * @var string Time string of the last possible time for repetition
     */
    protected $repeatPeriodEnd;

    /**
     * @return bool
     */
    public function isStartDateAllDay()
    {
        return !!$this->startDateAllDay;
    }

    /**
     * Toggle whether `start_date` is all day
     *
     * @param bool $start_date_all_day
     * @return void
     */
    public function setStartDateAllDay($start_date_all_day)
    {
        $this->startDateAllDay = $start_date_all_day;
    }

    /**
     * @return bool
     */
    public function isEndDateAllDay()
    {
        return !!$this->endDateAllDay;
    }

    /**
     * Toggle whether `end_date` is all day
     *
     * @param bool $end_date_all_day
     * @return void
     */
    public function setEndDateAllDay($end_date_all_day)
    {
        $this->endDateAllDay = $end_date_all_day;
    }

    /**
     * @param int|null $now The timestamp to check against
     * @return bool
     */
    public function isActive($now = null)
    {
        return !!$this->getActiveRange($now);
    }

    /**
     * @return array|null Returns a list [ start, end ] or null if miss
     */
    public function getActiveRange($now = null)
    {
        if (!$now) {
            $now = \Core::make('helper/date')->getOverridableNow(true);
        }

        $dh = \Core::make('helper/date');

        if (!$this->repeats()) {
            $start_date = $this->getStartDate();
            $end_date = $this->getEndDate();

            $start_time = null;
            $end_time = null;

            $start_date_object = $dh->toDateTime($start_date, 'app');
            $end_date_object = $dh->toDateTime($end_date, 'app');
            if (is_object($start_date_object)) {
                $start_time = $start_date_object->getTimestamp();
            }
            if (is_object($end_date_object)) {
                $end_time = $end_date_object->getTimestamp();
            }
            if (!$start_date ) {
                return null;
            }
            if ($start_date && $start_time > $now) {
                return null;
            }
            if ($end_date && $end_time < $now) {
                return null;
            }

            if ($end_date) {
                return $this->rangeFromTime($start_time, $end_time);
            } else {
                return $this->rangeFromTime($start_time, PHP_INT_MAX);
            }
        } else {
            $startsOn = date('Y-m-d', strtotime($this->getStartDate()));
            $ymd = date('Y-m-d', $now);
            $dailyTimeStart = strtotime($ymd . ' ' . date('H:i:s', strtotime($this->getStartDate())));
            $dailyTimeEnd = strtotime($ymd . ' ' . date('H:i:s', strtotime($this->getEndDate())));

            if ($this->getStartDate() != '' && strtotime($this->getStartDate()) > $now) {
                return null;
            }
            if ($this->getRepeatPeriodEnd() != '' && strtotime($ymd) > strtotime($this->getRepeatPeriodEnd())) {
                return null;
            }

            switch ($this->getRepeatPeriod()) {

                case self::REPEAT_DAILY:
                    // number of days between now and the start
                    $numDays = round(($now - strtotime($startsOn)) / 86400);
                    if (($numDays % $this->getRepeatEveryNum()) == 0) {
                        if ($now >= $dailyTimeStart && $now <= $dailyTimeEnd) {
                            return $this->rangeFromTime($dailyTimeStart);
                        }
                    }
                    break;

                case self::REPEAT_WEEKLY:
                    $start_time = new \DateTime();
                    $start_time->setTimestamp(strtotime($startsOn));

                    $now_time = new \DateTime();
                    $now_time->setTimestamp($now);

                    $week_diff_start = new \DateTime();
                    if (($days_past_sunday = date('w', $start_time->getTimestamp())) !== 0) {
                        $week_diff_start->setTimestamp(
                            strtotime("-{$days_past_sunday} days", $start_time->getTimestamp()));
                    } else {
                        $week_diff_start->setTimestamp($start_time->getTimestamp());
                    }

                    $week_diff_now = new \DateTime();
                    if (($days_past_sunday = date('w', $now_time->getTimestamp())) !== 0) {
                        $week_diff_now->setTimestamp(strtotime("-{$days_past_sunday} days", $now_time->getTimestamp()));
                    } else {
                        $week_diff_now->setTimestamp($now_time->getTimestamp());
                    }

                    $diff = $week_diff_now->diff($week_diff_start);
                    $num_weeks = floor($diff->days / 7);
<commit_msg>Use lazy comparison between result of date() and number<commit_after><?php
namespace Concrete\Core\Foundation\Repetition;

/**
 * Abstract repetition class
 * This class is used to define and match against various time windows
 *
 * @package Concrete\Core\Foundation\Repetition
 */
abstract class AbstractRepetition implements RepetitionInterface
{

    /**
     * @var string Date string of the start date/time
     */
    protected $startDate;

    /**
     * @var string Date string of the end date/time
     */
    protected $endDate;

    /**
     * @var bool Does the startDate include a time or should we just use the entire day?
     */
    protected $startDateAllDay;

    /**
     * @var bool Does the endDate include a time, or should we just use the entire day?
     */
    protected $endDateAllDay;

    /**
     * @var int self::REPEAT_* enum [ ::REPEAT_DAILY | ::REPEAT_WEEKLY | ::REPEAT_MONTHLY ]
     */
    protected $repeatPeriod;

    /**
     * @var int[] List of numeric representations of the day of the week 0 for sunday, 6 for saturday.
     */
    protected $repeatPeriodWeekDays;

    /**
     * @var int Number for the `repeatPeriod`
     */
    protected $repeatEveryNum;

    /**
     * @var int self::MONTHLY_REPEAT_* enum [ ::MONTHLY_REPEAT_WEEKLY | ::MONTHLY_REPEAT_MONTHLY | ::MONTHLY_REPEAT_LAST_WEEKDAY ]
     */
    protected $repeatMonthBy;

    /**
     * @var int The week day number
     */
    protected $repeatMonthLastWeekday;

    /**
     * @var string Time string of the last possible time for repetition
     */
    protected $repeatPeriodEnd;

    /**
     * @return bool
     */
    public function isStartDateAllDay()
    {
        return !!$this->startDateAllDay;
    }

    /**
     * Toggle whether `start_date` is all day
     *
     * @param bool $start_date_all_day
     * @return void
     */
    public function setStartDateAllDay($start_date_all_day)
    {
        $this->startDateAllDay = $start_date_all_day;
    }

    /**
     * @return bool
     */
    public function isEndDateAllDay()
    {
        return !!$this->endDateAllDay;
    }

    /**
     * Toggle whether `end_date` is all day
     *
     * @param bool $end_date_all_day
     * @return void
     */
    public function setEndDateAllDay($end_date_all_day)
    {
        $this->endDateAllDay = $end_date_all_day;
    }

    /**
     * @param int|null $now The timestamp to check against
     * @return bool
     */
    public function isActive($now = null)
    {
        return !!$this->getActiveRange($now);
    }

    /**
     * @return array|null Returns a list [ start, end ] or null if miss
     */
    public function getActiveRange($now = null)
    {
        if (!$now) {
            $now = \Core::make('helper/date')->getOverridableNow(true);
        }

        $dh = \Core::make('helper/date');

        if (!$this->repeats()) {
            $start_date = $this->getStartDate();
            $end_date = $this->getEndDate();

            $start_time = null;
            $end_time = null;

            $start_date_object = $dh->toDateTime($start_date, 'app');
            $end_date_object = $dh->toDateTime($end_date, 'app');
            if (is_object($start_date_object)) {
                $start_time = $start_date_object->getTimestamp();
            }
            if (is_object($end_date_object)) {
                $end_time = $end_date_object->getTimestamp();
            }
            if (!$start_date ) {
                return null;
            }
            if ($start_date && $start_time > $now) {
                return null;
            }
            if ($end_date && $end_time < $now) {
                return null;
            }

            if ($end_date) {
                return $this->rangeFromTime($start_time, $end_time);
            } else {
                return $this->rangeFromTime($start_time, PHP_INT_MAX);
            }
        } else {
            $startsOn = date('Y-m-d', strtotime($this->getStartDate()));
            $ymd = date('Y-m-d', $now);
            $dailyTimeStart = strtotime($ymd . ' ' . date('H:i:s', strtotime($this->getStartDate())));
            $dailyTimeEnd = strtotime($ymd . ' ' . date('H:i:s', strtotime($this->getEndDate())));

            if ($this->getStartDate() != '' && strtotime($this->getStartDate()) > $now) {
                return null;
            }
            if ($this->getRepeatPeriodEnd() != '' && strtotime($ymd) > strtotime($this->getRepeatPeriodEnd())) {
                return null;
            }

            switch ($this->getRepeatPeriod()) {

                case self::REPEAT_DAILY:
                    // number of days between now and the start
                    $numDays = round(($now - strtotime($startsOn)) / 86400);
                    if (($numDays % $this->getRepeatEveryNum()) == 0) {
                        if ($now >= $dailyTimeStart && $now <= $dailyTimeEnd) {
                            return $this->rangeFromTime($dailyTimeStart);
                        }
                    }
                    break;

                case self::REPEAT_WEEKLY:
                    $start_time = new \DateTime();
                    $start_time->setTimestamp(strtotime($startsOn));

                    $now_time = new \DateTime();
                    $now_time->setTimestamp($now);

                    $week_diff_start = new \DateTime();
                    if (($days_past_sunday = date('w', $start_time->getTimestamp())) != 0) {
                        $week_diff_start->setTimestamp(
                            strtotime("-{$days_past_sunday} days", $start_time->getTimestamp()));
                    } else {
                        $week_diff_start->setTimestamp($start_time->getTimestamp());
                    }

                    $week_diff_now = new \DateTime();
                    if (($days_past_sunday = date('w', $now_time->getTimestamp())) != 0) {
                        $week_diff_now->setTimestamp(strtotime("-{$days_past_sunday} days", $now_time->getTimestamp()));
                    } else {
                        $week_diff_now->setTimestamp($now_time->getTimestamp());
                    }

                    $diff = $week_diff_now->diff($week_diff_start);
                    $num_weeks = floor($diff->days / 7);

{'fraction_non_alphanumeric': 0.1294042280589366, 'fraction_numerical': 0.0017616912235746316, 'mean_word_length': 1.774716729615641, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6986159', 'n_tokens_mistral': 3768, 'n_tokens_neox': 3567, 'n_words': 762}