<commit_before><?php
/**
 * digital-logsheets: A web-based application for tracking the playback of audio segments on a community radio station.
 * Copyright (C) 2015  <NAME>
 * Copyright (C) 2015-2017  <NAME>
 * Copyright (C) 2016-2017  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

require_once('errorContainers/SaveEpisodeErrors.php');
require_once('utilities/ValidatorUtility.php');

class EpisodeValidator {


    const EPISODE_MAX_LENGTH_HOURS = 24;
    const EPISODE_MIN_LENGTH_HOURS = 0.25;
    const AIR_BEFORE_CURRENT_DATE_LIMIT_DAYS = 31;
    const AIR_AFTER_CURRENT_DATE_LIMIT_DAYS = 31;

    const PRERECORD_BEFORE_CURRENT_DATE_LIMIT_DAYS = 62;
    const PRERECORD_AFTER_CURRENT_DATE_LIMIT_DAYS = 0;

    /**
     * @var Episode
     */
    private $episode;

    public function __construct($episode) {
        $this->episode = $episode;
    }

    public function checkDraftSaveValidity() {
        $errorsContainer = new SaveEpisodeErrors();

        $this->areRequiredFieldsPresent($errorsContainer);
        $this->isEpisodeLengthValid($errorsContainer);
        $this->isEpisodeAirDateValid($errorsContainer);
        $this->isEpisodePrerecordDateValid($errorsContainer);

        return $errorsContainer;
    }

    public function checkFinalSaveValidity() {
        $errorsContainer = new SaveEpisodeErrors();

        $this->areRequiredFieldsPresent($errorsContainer);
        $this->isEpisodeLengthValid($errorsContainer);
        $this->isEpisodeAirDateValid($errorsContainer);
        $this->isEpisodePrerecordDateValid($errorsContainer);
    }

    public static function getEpisodeEarlyLimit() {
        $episodeEarlyLimit = new DateTime('now', new DateTimeZone('America/Montreal'));
        $episodeEarlyLimit->sub(new DateInterval('P' . self::AIR_BEFORE_CURRENT_DATE_LIMIT_DAYS . 'D'));

        return $episodeEarlyLimit;
    }

    public static function getEpisodeLateLimit() {
        $episodeEarlyLimit = new DateTime('now', new DateTimeZone('America/Montreal'));
        $episodeEarlyLimit->add(new DateInterval('P' . self::AIR_AFTER_CURRENT_DATE_LIMIT_DAYS . 'D'));

        return $episodeEarlyLimit;
    }

    public static function getPrerecordDateEarlyDaysLimit() {
        return self::PRERECORD_BEFORE_CURRENT_DATE_LIMIT_DAYS;
    }

    public static function getPrerecordDateLateDaysLimit() {
        return self::PRERECORD_AFTER_CURRENT_DATE_LIMIT_DAYS;
    }

    public static function getMinEpisodeLengthInHours() {
        return self::EPISODE_MIN_LENGTH_HOURS;
    }
<commit_msg>Remove use of DateTime::sub() and ::add()<commit_after><?php
/**
 * digital-logsheets: A web-based application for tracking the playback of audio segments on a community radio station.
 * Copyright (C) 2015  <NAME>
 * Copyright (C) 2015-2017  <NAME>
 * Copyright (C) 2016-2017  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

require_once('errorContainers/SaveEpisodeErrors.php');
require_once('utilities/ValidatorUtility.php');

class EpisodeValidator {


    const EPISODE_MAX_LENGTH_HOURS = 24;
    const EPISODE_MIN_LENGTH_HOURS = 0.25;
    const AIR_BEFORE_CURRENT_DATE_LIMIT_DAYS = 31;
    const AIR_AFTER_CURRENT_DATE_LIMIT_DAYS = 31;

    const PRERECORD_BEFORE_CURRENT_DATE_LIMIT_DAYS = 62;
    const PRERECORD_AFTER_CURRENT_DATE_LIMIT_DAYS = 0;

    /**
     * @var Episode
     */
    private $episode;

    public function __construct($episode) {
        $this->episode = $episode;
    }

    public function checkDraftSaveValidity() {
        $errorsContainer = new SaveEpisodeErrors();

        $this->areRequiredFieldsPresent($errorsContainer);
        $this->isEpisodeLengthValid($errorsContainer);
        $this->isEpisodeAirDateValid($errorsContainer);
        $this->isEpisodePrerecordDateValid($errorsContainer);

        return $errorsContainer;
    }

    public function checkFinalSaveValidity() {
        $errorsContainer = new SaveEpisodeErrors();

        $this->areRequiredFieldsPresent($errorsContainer);
        $this->isEpisodeLengthValid($errorsContainer);
        $this->isEpisodeAirDateValid($errorsContainer);
        $this->isEpisodePrerecordDateValid($errorsContainer);
    }

    public static function getEpisodeEarlyLimit() {
        $episodeEarlyLimit = new DateTime('now', new DateTimeZone('America/Montreal'));
        $episodeEarlyLimit->modify('-' . self::AIR_AFTER_CURRENT_DATE_LIMIT_DAYS . ' days');

        return $episodeEarlyLimit;
    }

    public static function getEpisodeLateLimit() {
        $episodeLateLimit = new DateTime('now', new DateTimeZone('America/Montreal'));
        $episodeLateLimit->modify('+' . self::AIR_AFTER_CURRENT_DATE_LIMIT_DAYS . ' days');

        return $episodeLateLimit;
    }

    public static function getPrerecordDateEarlyDaysLimit() {
        return self::PRERECORD_BEFORE_CURRENT_DATE_LIMIT_DAYS;
    }

    public static function getPrerecordDateLateDaysLimit() {
        return self::PRERECORD_AFTER_CURRENT_DATE_LIMIT_DAYS;
    }

    public static function getMinEpisodeLengthInHours() {
        return self::EPISODE_MIN_LENGTH_HOURS;
    }

{'fraction_non_alphanumeric': 0.09090909090909091, 'fraction_numerical': 0.01048951048951049, 'mean_word_length': 3.874515879163439, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2765126', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1781, 'n_words': 461}