Array_To_CSV.php
3 years ago
Date_Format.php
3 years ago
Exact_Range.php
3 years ago
Number_Formatter.php
3 years ago
Option.php
3 years ago
Relative_Range.php
3 years ago
Request.php
3 years ago
Salt.php
3 years ago
Security.php
3 years ago
Singleton.php
3 years ago
String_Util.php
3 years ago
Timezone.php
3 years ago
URL.php
3 years ago
WP_Async_Request.php
3 years ago
Timezone.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Utils; |
| 4 | |
| 5 | class Timezone |
| 6 | { |
| 7 | public static function utc_timezone() |
| 8 | { |
| 9 | return new \DateTimeZone('UTC'); |
| 10 | } |
| 11 | public static function utc_offset() |
| 12 | { |
| 13 | return '+00:00'; |
| 14 | } |
| 15 | public static function local_timezone() |
| 16 | { |
| 17 | return new \DateTimeZone(self::local_offset()); |
| 18 | } |
| 19 | // Will return an offset using the WordPress timezone set by the user |
| 20 | // Example return values: -04:00, +00:00, or +5:45 |
| 21 | public static function local_offset() |
| 22 | { |
| 23 | // Start with the offset such as -4, 0, or 5.75 |
| 24 | $offset_number = (float) \get_option('gmt_offset'); |
| 25 | // Build a string to represent the offset such as -04:00, +00:00, or +5:45 |
| 26 | $result = ''; |
| 27 | // Start with either - or + |
| 28 | $result .= $offset_number < 0 ? '-' : '+'; |
| 29 | $whole_part = \abs($offset_number); |
| 30 | $hour_part = \floor($whole_part); |
| 31 | $minute_part = $whole_part - $hour_part; |
| 32 | $hours = \strval($hour_part); |
| 33 | $minutes = \strval($minute_part * 60); |
| 34 | // Add hour part to result |
| 35 | $result .= \str_pad($hours, 2, '0', \STR_PAD_LEFT); |
| 36 | // Add separator |
| 37 | $result .= ':'; |
| 38 | // Add minute part to result |
| 39 | $result .= \str_pad($minutes, 2, '0', \STR_PAD_LEFT); |
| 40 | return $result; |
| 41 | } |
| 42 | } |
| 43 |