<commit_before><?php

namespace Iodev\Whois\Helpers;

class DateHelper
{
    /**
     * @param string $datestamp
     * @return int
     */
    public static function parseDate($datestamp)
    {
        $s = trim($datestamp);
        if (preg_match('/^\d{2}[-\s]+\w+[-\s]+\d{4}[-\s]+\d{2}:\d{2}(:\d{2})?([-\s]+\w+)?/ui', $s)) {
            return (int)strtotime($s);
        }
        if (preg_match('/^(\d{4})\.\s*(\d{2})\.\s*(\d{2})\.?\s*$/ui', $s, $m)) {
            $s = "{$m[1]}-{$m[2]}-{$m[3]}T00:00:00";
        } elseif (preg_match('/^\d{4}\.\d{2}\.\d{2}\s+\d{2}:\d{2}:\d{2}/ui', $s)) {
            $s = str_replace(".", "-", $s);
        } elseif (preg_match('/^(\d{2})-(\w+)-(\d{4})\s+(\d{2}:\d{2}:\d{2})/ui', $s, $m)) {
            $mon = self::textMonthToDigital($m[2]);
            $s = "{$m[3]}-{$mon}-{$m[1]}T{$m[4]}";
        } elseif (preg_match('/^(\d{2})[-\.](\d{2})[-\.](\d{4})$/ui', $s, $m)) {
            $s = "{$m[3]}-{$m[2]}-{$m[1]}T00:00:00";
        } elseif (preg_match('/^(\d{2})[-\s]+(\w+)[-\s]+(\d{4})/ui', $s, $m)) {
            $mon = self::textMonthToDigital($m[2]);
            $s = "{$m[3]}-{$mon}-{$m[1]}T00:00:00";
        } elseif (preg_match('/^(\d{4})(\d{2})(\d{2})$/ui', preg_replace('/\s*#.*/ui', '', $s), $m)) {
            $s = "{$m[1]}-{$m[2]}-{$m[3]}T00:00:00";
        } elseif (preg_match('~^(\d{2})/(\d{2})/(\d{4})$~ui', $s, $m)) {
            $s = "{$m[3]}-{$m[2]}-{$m[1]}T00:00:00";
        } elseif (preg_match('/^(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2}:\d{2})\s+\(GMT([-+]\d+:\d{2})\)$/ui', $s, $m)) {
            $s = "{$m[1]}T{$m[2]}{$m[3]}";
        }
        return (int)strtotime($s);
    }

    /**
     * @param $mon<commit_msg>fix (helpers): fix timezone parsing for php 5.4<commit_after><?php

namespace Iodev\Whois\Helpers;

class DateHelper
{
    /**
     * @param string $datestamp
     * @return int
     */
    public static function parseDate($datestamp)
    {
        $s = trim($datestamp);
        if (preg_match('/^\d{2}[-\s]+\w+[-\s]+\d{4}[-\s]+\d{2}:\d{2}(:\d{2})?([-\s]+\w+)?/ui', $s)) {
            // pass
        } elseif (preg_match('/^(\d{4})\.\s*(\d{2})\.\s*(\d{2})\.?\s*$/ui', $s, $m)) {
            $s = "{$m[1]}-{$m[2]}-{$m[3]}T00:00:00";
        } elseif (preg_match('/^\d{4}\.\d{2}\.\d{2}\s+\d{2}:\d{2}:\d{2}/ui', $s)) {
            $s = str_replace(".", "-", $s);
        } elseif (preg_match('/^(\d{2})-(\w+)-(\d{4})\s+(\d{2}:\d{2}:\d{2})/ui', $s, $m)) {
            $mon = self::textMonthToDigital($m[2]);
            $s = "{$m[3]}-{$mon}-{$m[1]}T{$m[4]}";
        } elseif (preg_match('/^(\d{2})[-\.](\d{2})[-\.](\d{4})$/ui', $s, $m)) {
            $s = "{$m[3]}-{$m[2]}-{$m[1]}T00:00:00";
        } elseif (preg_match('/^(\d{2})[-\s]+(\w+)[-\s]+(\d{4})/ui', $s, $m)) {
            $mon = self::textMonthToDigital($m[2]);
            $s = "{$m[3]}-{$mon}-{$m[1]}T00:00:00";
        } elseif (preg_match('/^(\d{4})(\d{2})(\d{2})$/ui', preg_replace('/\s*#.*/ui', '', $s), $m)) {
            $s = "{$m[1]}-{$m[2]}-{$m[3]}T00:00:00";
        } elseif (preg_match('~^(\d{2})/(\d{2})/(\d{4})$~ui', $s, $m)) {
            $s = "{$m[3]}-{$m[2]}-{$m[1]}T00:00:00";
        } elseif (preg_match('/^(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2}:\d{2})\s+\(GMT([-+]\d+:\d{2})\)$/ui', $s, $m)) {
            $s = "{$m[1]}T{$m[2]}{$m[3]}";
        }
        // Fix timezone parsing for PHP 5.4
        if (version_compare(PHP_VERSION, '5.5.0', '<')) {
            $s = str_replace('WAT', '+0100', $s);
        }
        return (int)strtotime($s);
    }

    /**
     * @param $mon
{'fraction_non_alphanumeric': 0.3789205990392766, 'fraction_numerical': 0.05340491664311953, 'mean_word_length': 2.2065217391304346, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, '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': '2963323', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1691, 'n_words': 174}