my website banner

modified for summer/winter time shifts
authorDavid Polakovic <email@dpolakovic.space>
Sun, 30 Mar 2025 09:48:21 +0000 (11:48 +0200)
committerDavid Polakovic <email@dpolakovic.space>
Sun, 30 Mar 2025 09:48:21 +0000 (11:48 +0200)
mars-clock.php
php/time.php [changed mode: 0755->0644]

index 7e3aa4369425976b831f8874a698ead18420c7fe..7f1d7c1420998582f6e384a04196c6eef85acf1e 100755 (executable)
 ------------------------------------------------------
 Earth                  |  Time   |       Date        |
 ------------------------------------------------------
-Silicon Valley         |  <?php timeEarth(-8) ?>  |  <?php dateEarth(-8) ?>  |
-Boston                 |  <?php timeEarth(-5) ?>  |  <?php dateEarth(-5) ?>  |
-London*                |  <?php timeEarth(0) ?>  |  <?php dateEarth(0) ?>  |
-Tokyo                  |  <?php timeEarth(9) ?>  |  <?php dateEarth(9) ?>  |
+Silicon Valley         |  <?php timeEarth("America/Los_Angeles") ?>  |  <?php dateEarth("America/Los_Angeles") ?>  |
+Boston                 |  <?php timeEarth("America/New_York") ?>  |  <?php dateEarth("America/New_York") ?>  |
+London*                |  <?php timeEarth("Europe/London") ?>  |  <?php dateEarth("Europe/London") ?>  |
+Tokyo                  |  <?php timeEarth("Asia/Tokyo") ?>  |  <?php dateEarth("Asia/Tokyo") ?>  |
 
 ------------------------------------------------------
 Mars                   |  Time   |       Date        |
old mode 100755 (executable)
new mode 100644 (file)
index dfcc234..8a6905b
@@ -8,29 +8,22 @@ function title() {
     //echo "Data valid to time: ". $current_time . "<br>";
 }
 
- function timeEarth($offset) {
-
-    $dateTime = new DateTime("now", new DateTimeZone("UTC"));
-    
-    // Modify the timezone using the provided offset
-    $timezoneName = sprintf("Etc/GMT%+d", -$offset);
-    $dateTime->setTimezone(new DateTimeZone($timezoneName));
-    
-    // Print the formatted time
-    echo $dateTime->format("H:i");
-
+function timeEarth($timezone) {
+    try {
+        $dateTime = new DateTime("now", new DateTimeZone($timezone));
+        echo $dateTime->format("H:i");
+    } catch (Exception $e) {
+        echo "Invalid timezone provided.";
+    }
 }
 
- function dateEarth(int $offset) {
-    // Create a DateTime object for the current date
-    $dateTime = new DateTime("now", new DateTimeZone("UTC"));
-    
-    // Modify the timezone using the provided offset
-    $timezoneName = sprintf("Etc/GMT%+d", -$offset);
-    $dateTime->setTimezone(new DateTimeZone($timezoneName));
-    
-    // Print the formatted date
-    echo $dateTime->format("d-m(M)-Y");
+function dateEarth($timezone) {
+    try {
+        $dateTime = new DateTime("now", new DateTimeZone($timezone));
+        echo $dateTime->format("d-m(M)-Y");
+    } catch (Exception $e) {
+        echo "Invalid timezone provided";
+    }
 }
 
 function get_time_m(){