Skip to content

Commit

Permalink
Update PicoDatabase.php
Browse files Browse the repository at this point in the history
  • Loading branch information
kamshory committed Nov 24, 2024
1 parent 5672d94 commit 89f80cd
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Database/PicoDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,19 @@ private static function getTimeZoneOffset($pdo)
}

/**
* Converts a timezone offset string to a PHP timezone name.
* Converts a timezone offset string to a corresponding PHP timezone name.
*
* This method takes an offset string (e.g., "+08:00" or "-05:30"), calculates the total offset
* in seconds, and attempts to find the corresponding PHP timezone name. If no matching timezone
* is found, it falls back to returning a UTC-based timezone string.
* This method takes a timezone offset string (e.g., "+08:00" or "-05:30") and computes
* the total offset in seconds. It then attempts to map the offset to a standard PHP
* timezone name. If no matching timezone is found, it falls back to returning a
* UTC-based timezone string in the same offset format.
*
* Examples:
* - Input: "+07:00" -> Output: "Asia/Jakarta" (if mapping exists).
* - Input: "-05:30" -> Output: "UTC-05:30" (fallback if no mapping exists).
*
* @param string $offset The timezone offset string (e.g., "+08:00", "-05:30").
* @return string The PHP timezone name, or a fallback UTC offset string.
* @return string The corresponding PHP timezone name, or a fallback UTC offset string (e.g., "UTC+08:00").
*/
private static function convertOffsetToTimeZone($offset)
{
Expand Down Expand Up @@ -271,7 +276,7 @@ private static function convertOffsetToTimeZone($offset)
return $timeZone;
} catch (Exception $e) {
// Handle any exceptions by returning an error message
return "Error: " . $e->getMessage();
return "UTC+00:00";
}
}

Expand Down

0 comments on commit 89f80cd

Please sign in to comment.