<commit_before><?php

namespace UAM\Twig\Extension\I18n;

use DateInterval;
use DateTime;
use Locale;
use Twig_Extension;
use Twig_SimpleFilter;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Loader\JsonFileLoader;

class DurationExtension extends Twig_Extension
{
    const CATALOGUE = 'uam-18n';
    const YEAR = 'y';
    const YEAR_FULL = 'Y';
    const MONTH = 'm';
    const DAY = 'd';
    const HOUR = 'h';
    const MINUTE = 'i';
    const SECOND = 's';
    const ROUND_VALUE_MONTH = 6;
    const ROUND_VALUE_DAY = 15;
    const ROUND_VALUE_HOUR = 12;
    const ROUND_VALUE_MINUTE = 30;
    const ROUND_VALUE_SECOND = 30;

    protected $factor = array(
        'ym' => 12,
        'dh' => 24,
        'di' => 1440,
        'ds' => 86400,
        'hi' => 60,
        'hs' => 3600,
        'is' => 60,
    );

    protected static $units = array(
        'y' => 'duration.year.short',
        'yy' => 'duration.year.medium',
        'yyy' => 'duration.year.full',
        'm' => 'duration.month.short',
        'mm' => 'duration.month.medium',
        'mmm' => 'duration.month.full',
        'd' => 'duration.day.short',
        'dd' => 'duration.day.medium',
        'ddd' => 'duration.day.full',
        'h' => 'duration.hour.short',
        'hh' => 'duration.hour.medium',
        'hhh' => 'duration.hour.full',
        'i' => 'duration.minute.short',
        'ii' => 'duration.minute.medium',
        'iii' => 'duration.minute.full',
        's' => 'duration.second.short',
        'ss' => 'duration.second.medium',
        'sss' => 'duration.second.full',
    );

    private $translator;

    public function getFilters()
    {
        return array(
            new Twig_SimpleFilter('duration', array($this, 'duration'), array('is_safe' => array('html'))),
        );
    }

    public function getName()
    {
        return 'duration';
    }

    public function duration($from, $to, $format='YYY-MMM-DDD-HHH-III-SSS', $locale = null)
    {
        $interval = self::getDateInterval($from, $to, $format);

        $locale = $locale !== null ? $locale : Locale::getDefault();

        $duration = $interval;

        $result = '';

        $formats = explode('-', $format);

        $result = array();

        $regexes = array(
            '/^[yY]{1,3}/' => '%y' ,
            '/^[mM]{1,3}/' => '%m',
            '/^[dD]{1,3}/' => '%d',
            '/^[hH]{1,3}/' => '%h',
            '/^[iI]{1,3}/' => '%i',
            '/^[sS]{1,3}/' => '%s',
        );

        $n = count($formats);

        foreach ($formats as $i => $format) {

            foreach ($regexes as $regex => $date_format) {
                if (preg_match($regex, $format, $matches)) {
                    $value = $duration->format($date_format);

                    if (0 == $value) {

                        if ($format == ctype_lower($format)) {
                            continue;
                        }
                    }

                    $unit = $this->getUnit(strtolower($format));

                    $result[] = $this->trans($unit, $value, $locale);

                    break;
                }
            }
        }<commit_msg>fixed some variables<commit_after><?php

namespace UAM\Twig\Extension\I18n;

use DateInterval;
use DateTime;
use Locale;
use Twig_Extension;
use Twig_SimpleFilter;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Loader\JsonFileLoader;

class DurationExtension extends Twig_Extension
{
    const CATALOGUE = 'uam-18n';
    const YEAR = 'y';
    const MONTH = 'm';
    const DAY = 'd';
    const HOUR = 'h';
    const MINUTE = 'i';
    const SECOND = 's';
    const ROUND_VALUE_MONTH = 6;
    const ROUND_VALUE_DAY = 15;
    const ROUND_VALUE_HOUR = 12;
    const ROUND_VALUE_MINUTE = 30;
    const ROUND_VALUE_SECOND = 30;

    protected $factor = array(
        'ym' => 12,
        'dh' => 24,
        'di' => 1440,
        'ds' => 86400,
        'hi' => 60,
        'hs' => 3600,
        'is' => 60,
    );

    protected static $units = array(
        'y' => 'duration.year.short',
        'yy' => 'duration.year.medium',
        'yyy' => 'duration.year.full',
        'm' => 'duration.month.short',
        'mm' => 'duration.month.medium',
        'mmm' => 'duration.month.full',
        'd' => 'duration.day.short',
        'dd' => 'duration.day.medium',
        'ddd' => 'duration.day.full',
        'h' => 'duration.hour.short',
        'hh' => 'duration.hour.medium',
        'hhh' => 'duration.hour.full',
        'i' => 'duration.minute.short',
        'ii' => 'duration.minute.medium',
        'iii' => 'duration.minute.full',
        's' => 'duration.second.short',
        'ss' => 'duration.second.medium',
        'sss' => 'duration.second.full',
    );

    private $translator;

    public function getFilters()
    {
        return array(
            new Twig_SimpleFilter('duration', array($this, 'duration'), array('is_safe' => array('html'))),
        );
    }

    public function getName()
    {
        return 'duration';
    }

    public function duration($from, $to, $format='YYY-MMM-DDD-HHH-III-SSS', $locale = null)
    {
        $interval = self::getDateInterval($from, $to, $format);

        $locale = $locale !== null ? $locale : Locale::getDefault();

        $duration = $interval;

        $result = '';

        $formats = explode('-', $format);

        $result = array();

        $regexes = array(
            '/^[yY]{1,3}/' => '%y' ,
            '/^[mM]{1,3}/' => '%m',
            '/^[dD]{1,3}/' => '%d',
            '/^[hH]{1,3}/' => '%h',
            '/^[iI]{1,3}/' => '%i',
            '/^[sS]{1,3}/' => '%s',
        );

        $n = count($formats);

        foreach ($formats as $i => $format) {

            foreach ($regexes as $regex => $date_format) {
                if (preg_match($regex, $format, $matches)) {
                    $value = $duration->format($date_format);

                    if (0 == $value) {
                        if ($format == ctype_lower($format)) {
                            continue;
                        }
                    }

                    $unit = $this->getUnit(strtolower($format));

                    $result[] = $this->trans($unit, $value, $locale);

                    break;
                }
            }
        }
{'fraction_non_alphanumeric': 0.1786214407966392, 'fraction_numerical': 0.014625797417146414, 'mean_word_length': 1.8267370272647319, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 77, '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': '1328474', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2028, 'n_words': 413}