<commit_before><?php
/**
 * This file is part of the Emperor Norton Commands.
 *
 * Public domain. All rites reversed.
 */

namespace EmperorNortonCommands\lib;

/**
 * Class DdateConverter.
 *
 * Converts Gregorian dates to Discordian dates.
 * @package EmperorNortonCommands\lib
 */
class DdateConverter
{
    /**
     * Curse of Greyface.
     *
     * The Curse of Greyface occurred in 1 YOLD and thus defines the offset
     * from the Gregorian calendar, according to which it was 1166 BC.
     *
     * @var integer
     */
    protected $_curseOfGreyface = 1166;

    /**
     * Discordian Holydays.
     *
     * @var string[]
     */
    protected $_holydays = array(
        '0501' => 'Mungday',
        '1902' => 'Chaoflux',
        '1903' => 'Mojoday',
        '0305' => 'Discoflux',
        '3105' => 'Syaday',
        '1507' => 'Conflux',
        '1208' => 'Zaraday',
        '2609' => 'Bureflux',
        '2410' => 'Maladay',
        '0812' => 'Afflux'
    );

    /**
     * Convert Gregorian to Discordian Date.
     *
     * @param \DateTime $date
     * @return DdateValue
     */
    public function convert(\DateTime $date)
    {
        if ($this->_isStTibsDay($date->format('m'), $date->format('d')))
        {
            return $this->_calculateDdateStTibs($date);
        }
        return $this->_calculateDdate($date);
    }

    /**
     * Conversion algorithm for St. Tibs Day.
     *
     * @param \DateTime $date
     * @return DdateValue
     */
    protected function _calculateDdateStTibs(\DateTime $date)
    {
        $ddate = new DdateValue();
        $ddate->setDay(DdateValue::ST_TIBS_DAY);
        $ddate->setSeason(DdateValue::ST_TIBS_DAY);
        $ddate->setWeekDay(DdateValue::ST_TIBS_DAY);
        $ddate->setYear($this->_calculateYear($date));
        $ddate->setDaysUntilXDay($this->_calculateDaysUntilXday($date));
        $ddate->setHolyday($this->_holydays['2902']);
        return $ddate;
    }

    /**
     * Regular conversion algorithm.
     *
     * @param \DateTime $date
     * @return DdateValue
     */
    protected function _calculateDdate(\DateTime $date)
    {
        $ddate = new DdateValue();
        $ddate->setDay($this->_calculateDayofSeason($date));
        $ddate->setSeason($this->_calculateSeason($date));
        $ddate->setWeekDay($this->_calculateDayOfWeek($date));
        $ddate->setYear($this->_calculateYear($date));
        $ddate->setDaysUntilXDay($this->_calculateDaysUntilXday($date));
        $ddate->setHolyday($this->_getHolyday($date));
        return $ddate;
    }

    /**
     * Get Holyday.
     *
     * Returns empty string if $date is not a Holyday.
     *
     * @param \DateTime $date
     * @return string
     */
    protected function _getHolyday(\DateTime $date)<commit_msg>Fix bug.<commit_after><?php
/**
 * This file is part of the Emperor Norton Commands.
 *
 * Public domain. All rites reversed.
 */

namespace EmperorNortonCommands\lib;

/**
 * Class DdateConverter.
 *
 * Converts Gregorian dates to Discordian dates.
 * @package EmperorNortonCommands\lib
 */
class DdateConverter
{
    /**
     * Curse of Greyface.
     *
     * The Curse of Greyface occurred in 1 YOLD and thus defines the offset
     * from the Gregorian calendar, according to which it was 1166 BC.
     *
     * @var integer
     */
    protected $_curseOfGreyface = 1166;

    /**
     * Discordian Holydays.
     *
     * @var string[]
     */
    protected $_holydays = array(
        '0501' => 'Mungday',
        '1902' => 'Chaoflux',
        '1903' => 'Mojoday',
        '0305' => 'Discoflux',
        '3105' => 'Syaday',
        '1507' => 'Conflux',
        '1208' => 'Zaraday',
        '2609' => 'Bureflux',
        '2410' => 'Maladay',
        '0812' => 'Afflux'
    );

    /**
     * Convert Gregorian to Discordian Date.
     *
     * @param \DateTime $date
     * @return DdateValue
     */
    public function convert(\DateTime $date)
    {
        if ($this->_isStTibsDay($date->format('m'), $date->format('d')))
        {
            return $this->_calculateDdateStTibs($date);
        }
        return $this->_calculateDdate($date);
    }

    /**
     * Conversion algorithm for St. Tibs Day.
     *
     * @param \DateTime $date
     * @return DdateValue
     */
    protected function _calculateDdateStTibs(\DateTime $date)
    {
        $ddate = new DdateValue();
        $ddate->setDay(DdateValue::ST_TIBS_DAY);
        $ddate->setSeason(DdateValue::ST_TIBS_DAY);
        $ddate->setWeekDay(DdateValue::ST_TIBS_DAY);
        $ddate->setYear($this->_calculateYear($date));
        $ddate->setDaysUntilXDay($this->_calculateDaysUntilXday($date));
        return $ddate;
    }

    /**
     * Regular conversion algorithm.
     *
     * @param \DateTime $date
     * @return DdateValue
     */
    protected function _calculateDdate(\DateTime $date)
    {
        $ddate = new DdateValue();
        $ddate->setDay($this->_calculateDayofSeason($date));
        $ddate->setSeason($this->_calculateSeason($date));
        $ddate->setWeekDay($this->_calculateDayOfWeek($date));
        $ddate->setYear($this->_calculateYear($date));
        $ddate->setDaysUntilXDay($this->_calculateDaysUntilXday($date));
        $ddate->setHolyday($this->_getHolyday($date));
        return $ddate;
    }

    /**
     * Get Holyday.
     *
     * Returns empty string if $date is not a Holyday.
     *
     * @param \DateTime $date
     * @return string
     */
    protected function _getHolyday(\DateTime $date)
{'fraction_non_alphanumeric': 0.1448589626933576, 'fraction_numerical': 0.01856232939035487, 'mean_word_length': 2.343065693430657, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, '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': '6979921', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1767, 'n_words': 355}