Ver código fonte

Added timezone parameter for time comparisation when timezones from radio is different

Janco Kock 9 anos atrás
pai
commit
fc190b0eaf
2 arquivos alterados com 13 adições e 4 exclusões
  1. 9 2
      getAlarmen.php
  2. 4 2
      gettimezone.php

+ 9 - 2
getAlarmen.php

@@ -3,7 +3,9 @@
 	include_once('includes/global_functions.php');
     $radioid = $_GET['radioid'];
     $radiomac = $_GET['radiomac'];
-        
+    $tz = $_GET['tz'];
+    
+
     if($radioid == "" && $radiomac == ""){
         print(json_encode([error => "Not a valid radioid"]));
         die();
@@ -20,7 +22,12 @@
         	$stmt -> bind_result($id, $message, $message, $streamip, $streamurl, $streamport, $tijdstr, $snoozetijd);
         	while($result = $stmt -> fetch()){
         	    $tijd = strtotime($tijdstr);
-        	    if($tijd < time()){
+        	    
+        	    $timezone_name = timezone_name_from_abbr('', $tz * 3600, true);
+        	    $datTimeZoneuser = new DateTimeZone($timezone_name);
+        	    $time = new DateTime('now', $datTimeZoneuser );
+        	    
+        	    if($tijd < strtotime($time->format("Y-m-d H:i:s   "))){
         	       $tijd = strtotime($tijdstr.' +1 day');
         	    }
         	    array_push($array, array(   YYYY=> date("Y", $tijd), 

+ 4 - 2
gettimezone.php

@@ -11,11 +11,13 @@ $request_url = "https://maps.googleapis.com/maps/api/timezone/json?location=".$l
 $json = file_get_contents($request_url);
 $data = json_decode($json);
 
+
 $dateTimeZoneRemote = new DateTimeZone($data->timeZoneId);
 $timeRemote = new DateTime('now', $dateTimeZoneRemote);
-$datTimeZoneUtc = new DateTimeZone("Europe/London");
+$datTimeZoneUtc = new DateTimeZone('UTC');
+$timelocal = new DateTime('now', $datTimeZoneUtc);
 
-$offset = $dateTimeZoneRemote->getOffset( $timeRemote ) / 3600;
+$offset = $dateTimeZoneRemote->getOffset( $timelocal ) / 3600;
 echo $offset;
 
 ?>