First of all, I've done a lot of research here on the site and found no more in-depth example, just basic questions / answers about how to get the difference between dates, what I got to do and it works the way I want. >
However, the code I currently have seems to me a bit "heavy" but since I do not have advanced knowledge in PHP, I do not know how I could simplify it.
I have a JSON file with some data, some of which needs to be updated after 30 minutes have elapsed since its creation. For this I use the following code to create the time used in the json file:
'time' => date('m/d/Y H:i:s')
When I do the date request, I then compare the date saved in the json file, with the current date. If it's longer than 30 minutes, I have to do another treatment. This is the code I currently use:
$fileTime = new DateTime($file['time']); //Data obtida do arquivo json
$currTime = new DateTime();
$interval = date_diff($fileTime, $currTime);
if($interval->y >= 1 || $interval->m >= 1 || $interval->d >= 1 || $interval->h >= 1 || $interval->i >= 30) {
//Chama função
}
The problem with this is that if it takes 1:10 minutes and I check only the minutes, it will give a wrong result, since it's been over 30mins, so I have to check all the houses after the minute also.
Is there any way to simplify this verification?