A
A
Alexander Ampleev2018-07-31 11:32:54
linux
Alexander Ampleev, 2018-07-31 11:32:54

Why is the correct time returned only when called again?

I caught a very strange situation when moving from debian to centos to another server ..
In the view there is a time output like this:

var_dump(HtmlPurifier::process(NewTime::new_time(strtotime('2018-06-15 13:26:27'))));
var_dump(HtmlPurifier::process(NewTime::new_time(strtotime('2018-06-15 13:26:27'))));

The NewTime class when a long time ago just took it ready for translation into a readable date format:
<?php

namespace app\models;


class NewTime{

    public static function new_time($a) { // преобразовываем время в нормальный вид
        date_default_timezone_set('Europe/Moscow');
        $ndate = date('d.m.Y', $a);
        $ndate_time = date('H:i', $a);
        $ndate_exp = explode('.', $ndate);
        $nmonth = array(
            1 => 'января',
            2 => 'февраля',
            3 => 'марта',
            4 => 'апреля',
            5 => 'мая',
            6 => 'июня',
            7 => 'июля',
            8 => 'августа',
            9 => 'сентября',
            10 => 'октября',
            11 => 'ноября',
            12 => 'декабря'
        );

        foreach ($nmonth as $key => $value) {
            if($key == intval($ndate_exp[1])) $nmonth_name = $value;
        }

        if($ndate == date('d.m.Y')) return 'сегодня в '.$ndate_time;
        elseif($ndate == date('d.m.Y', strtotime('-1 day'))) return 'вчера в '.$ndate_time;
        else return $ndate_exp[0].' '.$nmonth_name.' '.$ndate_exp[2].' в '.$ndate_time;
    }

}

so, in the view, it would seem that 2 values ​​of the same should be displayed:
June 15, 2018 at 13:26
June 15, 2018 at 13:26
but it is displayed differently, but like this:
June 15, 2018 at 16:26
June 15, 2018 at 13: 26
i.e. At the first call, for some reason, it adds 3 hours, and at the second it doesn’t) What do you think? Why so?
For the time being, I just fixed it with an idle call at the beginning, and as a result, the correct time is returned ..

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question