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
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.php
3 years ago
timezone.php
3 years ago
url.php
3 years ago
wp-async-request.php
3 years ago
timezone.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | class Timezone |
| 6 | { |
| 7 | public static function utc_timezone() |
| 8 | { |
| 9 | return new \DateTimeZone('UTC'); |
| 10 | } |
| 11 | |
| 12 | public static function utc_offset() |
| 13 | { |
| 14 | return '+00:00'; |
| 15 | } |
| 16 | |
| 17 | public static function local_timezone() |
| 18 | { |
| 19 | return new \DateTimeZone(self::local_offset()); |
| 20 | } |
| 21 | |
| 22 | // Will return an offset using the WordPress timezone set by the user |
| 23 | // Example return values: -04:00, +00:00, or +5:45 |
| 24 | public static function local_offset() |
| 25 | { |
| 26 | // Start with the offset such as -4, 0, or 5.75 |
| 27 | $offset_number = (float) get_option('gmt_offset'); |
| 28 | |
| 29 | // Build a string to represent the offset such as -04:00, +00:00, or +5:45 |
| 30 | $result = ''; |
| 31 | |
| 32 | // Start with either - or + |
| 33 | $result .= $offset_number < 0 ? '-' : '+'; |
| 34 | |
| 35 | $whole_part = abs($offset_number); |
| 36 | $hour_part = floor($whole_part); |
| 37 | $minute_part = $whole_part - $hour_part; |
| 38 | |
| 39 | $hours = strval($hour_part); |
| 40 | $minutes = strval($minute_part * 60); |
| 41 | |
| 42 | // Add hour part to result |
| 43 | $result .= str_pad($hours, 2, '0', STR_PAD_LEFT); |
| 44 | |
| 45 | // Add separator |
| 46 | $result .= ':'; |
| 47 | |
| 48 | // Add minute part to result |
| 49 | $result .= str_pad($minutes, 2, '0', STR_PAD_LEFT); |
| 50 | |
| 51 | return $result; |
| 52 | } |
| 53 | } |
| 54 |