PHP strtotime function returns wrong time?

Hi there;

Is there a setting I need to change somewhere ? The strtotime function appears to be returning the wrong time ?

This is my code

		$pregresult = preg_match("/\"dateTime\":\"([0-9]{2}\.[0-9]{2}\.[0-9]{4}\s[0-9]{2}:[0-9]{2}:[0-9]{2})/", $filedata, $matches); // GET BATTLE TIME
		if ((isset($matches[0])) and (isset($matches[1]))) {
echo "pregmatchedtime = " . $matches[1] . "<br>";
zprint($matches);
			$unixbattletime = strtotime($matches[1]);
			$actualtime = localtime(null, true);
			$localtime =	str_pad($actualtime["tm_mday"], 2, "0", STR_PAD_LEFT) . "." . str_pad(($actualtime["tm_mon"] + 1), 2, "0", STR_PAD_LEFT) . "." .
							($actualtime["tm_year"] + 1900) . " " . str_pad($actualtime["tm_hour"], 2, "0", STR_PAD_LEFT) . ":" .
							str_pad($actualtime["tm_min"], 2, "0", STR_PAD_LEFT) . ":" . str_pad($actualtime["tm_sec"], 2, "0", STR_PAD_LEFT);
			$unixlocaltime = strtotime($localtime);
			if (($unixbattletime > ($unixlocaltime + 1000)) or ($unixbattletime < ($unixlocaltime - 1000))) $foundtype1 = 0; // IF NEW BATTLE IS NOT ACTUALLY NEW, THEN DO NOT FLAG AS RECENT BATTLE
echo "unixbattletime = $unixbattletime<br>unixlocaltime = $unixlocaltime<br>foundtype1 = $foundtype1<br>";

When run from ExeOutput, example results are:

pregmatchedtime = 12.10.2023 12:29:40
Array
(
    [0] => "dateTime":"12.10.2023 12:29:40
    [1] => 12.10.2023 12:29:40
)
unixbattletime = 1697106580 // edit: Thu Oct 12 2023 10:29:40 GMT+0000
unixlocaltime = 1697110570 // edit: Thu Oct 12 2023 11:36:10 GMT+0000
foundtype1 = 0
currenttime = 1697110570
foundtype1 = 0
Replay uploaded at 12:36

D:/World_of_Tanks_EU/replays/20231012_1229_france-F38_Bat_Chatillon155_58_127_japort.wotreplay

When run from a browser (using XAMPP as the server):

pregmatchedtime = 12.10.2023 12:40:54
Array
(
    [0] => "dateTime":"12.10.2023 12:40:54
    [1] => 12.10.2023 12:40:54
)
unixbattletime = 1697110854 // edit: Thu Oct 12 2023 11:40:54 GMT+0000
unixlocaltime = 1697111224  // edit: Thu Oct 12 2023 11:47:04 GMT+0000
foundtype1 = 1
currenttime = 1697111224
foundtype1 = 1
Replay uploaded at 12:47

D:/World_of_Tanks_EU/replays/20231012_1240_france-F38_Bat_Chatillon155_58_05_prohorovka.wotreplay

The thing to look at is the “unixbattletime” in both outputs. You will see there is a 1 hour difference between the 2. The thing that is even more confusing is that the 2nd strtotime in the script appears to be working just fine !! Is this a bug or a setting I have set wrong on ExeOutput perhaps OR am I being totally thick and missing the obvious ?

Many thanks,

Zoe

What I am trying to actually do is this.

The files are battle files containing battle results from a computer game. The filename and the data in the file being looked at are saved in local time, whatever that timezone might be. The file may be being sent from anywhere in the world. I need to check that the file was created within a roughly 15/16 minute range of it being uploaded to make sure it is “recent” battle file and not one from longer ago than the 15/16 mins.

The time being sent to the server however is the current unix time, as the server has to be able to tell how long until the results are no longer useful.

I hope that makes some sense !!

Many thanks,

Zoe

Only things that comes to my mind is php.ini settings.

Default is:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Europe/Paris

Heya :slight_smile:

Ok but what happens when it’s run in timezones around the world ? I would have thought it would have adjusted automatically seeing as it’s designed to be portable and downloaded from anywhere ?

Many thanks,

Zoe

Thanks very much for that. Just about to start streaming right now but I will have a look afterwards.

Thanks so much :slight_smile:

Zoe

You can also tweak the time zone in the PHP.INI (by default, it’s set to Europe/Paris…)

Ok I’ll have a look at that.

Thanks very much,

Zoe

I actually came up with this…

		$matches = array();
		$pregresult = preg_match("/\"dateTime\":\"([0-9]{2}\.[0-9]{2}\.[0-9]{4}\s[0-9]{2}:[0-9]{2}:[0-9]{2})/", $filedata, $matches); // GET BATTLE TIME
		if ((isset($matches[0])) and (isset($matches[1]))) {
			$unixbattletime = strtotime($matches[1]);
			$localtime = trim(exec('powershell "Get-Date -Format \"dd.MM.yyyy HH:mm:ss\""'));
			$unixlocaltime = strtotime($localtime);
			if (($unixbattletime > ($unixlocaltime + 1020)) or ($unixbattletime < ($unixlocaltime - 1020))) $foundtype1 = 0; // IF FILE OUTSIDE +/-17mins, THEN DO NOT FLAG AS RECENT BATTLE
		}

This way, the timezone is irrelevant and no need to check daylight savings settings either.
Seems to work anyway. Now to get friends to test :slight_smile:

Zoe

Oh Poop,

It works in a browser with XAMPP but doesn’t work in ExeOutput. No errors - No nothing. It just stops the script from running/hangs.

Any ideas please ? There seems to be no output from that script after the exec() line would have been executed. The script runs in an iframe and is supposed to refresh every minute. The entire app hasn’t stopped though. I can still hit the back/home buttons etc.

It’s this line specifically:

$localtime = trim(exec('powershell "Get-Date -Format \"dd.MM.yyyy HH:mm:ss\""'));

Many thanks,

Zoe

It appears that the Powershell process is not completing/closing ?

Many thanks,

Zoe

Just discovered something else.

If I KILL the Powershell process before the 30 secs PHP max runtime is up, the command actually works and the script returns with the correct values !!!

:astonished:

Any thoughts would be appreciated :two_hearts:

It’s on our TODO list to review the problem for ExeOutput 2023. Thanks!