<commit_before><?php
/**
 * GpsLab component.
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2016, <NAME>
 * @license   http://opensource.org/licenses/MIT
 */

namespace GpsLab\Bundle\DateBundle;

use GpsLab\Bundle\DateBundle\Exception\InvalidCompareOperatorException;

class Comparator
{
    const EQ = '=';
    const NEQ = '!=';
    const LT = '<';
    const LTE = '<=';
    const GT = '>';
    const GTE = '>=';

    /**
     * Synonym for Comparator::compareDateTime().
     *
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compare(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($x, $operator, $y);
    }

    /**
     * Compare date and time.
     *
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareDateTime(\DateTime $x, $operator, \DateTime $y)
    {
        switch ($operator) {
            case self::EQ:
            case '==':
                return $x == $y;
            case self::NEQ:
            case '<>':
                return $x != $y;
            case self::GT:
                return $x > $y;
            case self::GTE:
                return $x >= $y;
            case self::LT:
                return $x < $y;
            case self::LTE:
                return $x <= $y;
            default:
                throw InvalidCompareOperatorException::create($operator);
        }
    }

    /**
     * Compare only date. Not compare time.
     *
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareDate(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($this->resetTime($x), $operator, $this->resetTime($y));
    }

    /**
     * Compare only time.
     *
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareTime(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($this->resetDate($x), $operator, $this->resetDate($y));
    }

    /**
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareWeek(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($this->resetWeek($x), $operator, $this->resetWeek($y));
    }

    /**
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareMonth(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($this->resetMonth($x), $operator, $this->resetMonth($y));
    }

    /**
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareYear(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($this->resetYear($x), $operator, $this->resetYear($y));
    }

    /**
     * @param \DateTime $date
     *
     * @return \DateTime
     */
    protected function resetTime(\DateTime $date)
    {
        $date = clone $date;
        $date->setTime(0, 0, 0);

        return $date;
    }

    /**
     * @param \DateTime $date
     *
     * @return \DateTime
     */
    protected function resetDate(\DateTime $date)
    {
        $date = clone $date;
        $date->setDate(1, 1, 1);

        return $date;
    }

    /**
     * @param \DateTime $date
     *
     * @return \DateTime
     */
    protected function resetWeek(\DateTime $date)
    {
        return Util::getMondayThisWeek($date)->setTime(0, 0, 0);
    }

    /**
     * @param \DateTime $date<commit_msg>use modify for reset week<commit_after><?php
/**
 * GpsLab component.
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2016, <NAME>
 * @license   http://opensource.org/licenses/MIT
 */

namespace GpsLab\Bundle\DateBundle;

use GpsLab\Bundle\DateBundle\Exception\InvalidCompareOperatorException;

class Comparator
{
    const EQ = '=';
    const NEQ = '!=';
    const LT = '<';
    const LTE = '<=';
    const GT = '>';
    const GTE = '>=';

    /**
     * Synonym for Comparator::compareDateTime().
     *
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compare(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($x, $operator, $y);
    }

    /**
     * Compare date and time.
     *
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareDateTime(\DateTime $x, $operator, \DateTime $y)
    {
        switch ($operator) {
            case self::EQ:
            case '==':
                return $x == $y;
            case self::NEQ:
            case '<>':
                return $x != $y;
            case self::GT:
                return $x > $y;
            case self::GTE:
                return $x >= $y;
            case self::LT:
                return $x < $y;
            case self::LTE:
                return $x <= $y;
            default:
                throw InvalidCompareOperatorException::create($operator);
        }
    }

    /**
     * Compare only date. Not compare time.
     *
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareDate(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($this->resetTime($x), $operator, $this->resetTime($y));
    }

    /**
     * Compare only time.
     *
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareTime(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($this->resetDate($x), $operator, $this->resetDate($y));
    }

    /**
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareWeek(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($this->resetWeek($x), $operator, $this->resetWeek($y));
    }

    /**
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareMonth(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($this->resetMonth($x), $operator, $this->resetMonth($y));
    }

    /**
     * @param \DateTime $x
     * @param string $operator
     * @param \DateTime $y
     *
     * @return bool
     */
    public function compareYear(\DateTime $x, $operator, \DateTime $y)
    {
        return $this->compareDateTime($this->resetYear($x), $operator, $this->resetYear($y));
    }

    /**
     * @param \DateTime $date
     *
     * @return \DateTime
     */
    protected function resetTime(\DateTime $date)
    {
        $date = clone $date;
        $date->setTime(0, 0, 0);

        return $date;
    }

    /**
     * @param \DateTime $date
     *
     * @return \DateTime
     */
    protected function resetDate(\DateTime $date)
    {
        $date = clone $date;
        $date->setDate(1, 1, 1);

        return $date;
    }

    /**
     * @param \DateTime $date
     *
     * @return \DateTime
     */
    protected function resetWeek(\DateTime $date)
    {
        $date = clone $date;
        $date->modify('Monday this week')->setTime(0, 0, 0);

        return $date;
    }

    /**
     * @param \DateTime $date
{'fraction_non_alphanumeric': 0.15299846232701178, 'fraction_numerical': 0.0033316248077908763, 'mean_word_length': 1.8055355859094178, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 60, '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': '3782513', 'n_tokens_mistral': 2433, 'n_tokens_neox': 2355, 'n_words': 577}