Skip to content

Commit

Permalink
Add timezone support
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhamp committed Jul 17, 2024
1 parent 66d990e commit db818a8
Show file tree
Hide file tree
Showing 2 changed files with 358 additions and 0 deletions.
344 changes: 344 additions & 0 deletions src/Support/Timezones.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,344 @@
<?php

namespace Native\Laravel\Support;

class Timezones
{
private array $windows = [
'Dateline Standard Time' => 'Etc/GMT+12',
'UTC-11' => 'Etc/GMT+11',
'Aleutian Standard Time' => 'America/Adak',
'Hawaiian Standard Time' => 'Pacific/Honolulu',
'Marquesas Standard Time' => 'Pacific/Marquesas',
'Alaskan Standard Time' => 'America/Anchorage',
'UTC-09' => 'Etc/GMT+9',
'Pacific Standard Time (Mexico)' => 'America/Tijuana',
'UTC-08' => 'Etc/GMT+8',
'Pacific Standard Time' => 'America/Los_Angeles',
'US Mountain Standard Time' => 'America/Phoenix',
'Mountain Standard Time (Mexico)' => 'America/Chihuahua',
'Mountain Standard Time' => 'America/Denver',
'Yukon Standard Time' => 'America/Whitehorse',
'Central America Standard Time' => 'America/Guatemala',
'Central Standard Time' => 'America/Chicago',
'Easter Island Standard Time' => 'Pacific/Easter',
'Central Standard Time (Mexico)' => 'America/Mexico_City',
'Canada Central Standard Time' => 'America/Regina',
'SA Pacific Standard Time' => 'America/Bogota',
'Eastern Standard Time (Mexico)' => 'America/Cancun',
'Eastern Standard Time' => 'America/New_York',
'Haiti Standard Time' => 'America/Port-au-Prince',
'Cuba Standard Time' => 'America/Havana',
'US Eastern Standard Time' => 'America/Indianapolis',
'Turks And Caicos Standard Time' => 'America/Grand_Turk',
'Paraguay Standard Time' => 'America/Asuncion',
'Atlantic Standard Time' => 'America/Halifax',
'Venezuela Standard Time' => 'America/Caracas',
'Central Brazilian Standard Time' => 'America/Cuiaba',
'SA Western Standard Time' => 'America/La_Paz',
'Pacific SA Standard Time' => 'America/Santiago',
'Newfoundland Standard Time' => 'America/St_Johns',
'Tocantins Standard Time' => 'America/Araguaina',
'E. South America Standard Time' => 'America/Sao_Paulo',
'Argentina Standard Time' => 'America/Argentina/Buenos_Aires',
'Greenland Standard Time' => 'America/Godthab',
'Montevideo Standard Time' => 'America/Montevideo',
'Magallanes Standard Time' => 'America/Punta_Arenas',
'Saint Pierre Standard Time' => 'America/Miquelon',
'Bahia Standard Time' => 'America/Bahia',
'UTC-02' => 'Etc/GMT+2',
'Azores Standard Time' => 'Atlantic/Azores',
'Cape Verde Standard Time' => 'Atlantic/Cape_Verde',
'UTC' => 'Etc/UTC',
'GMT Standard Time' => 'Europe/London',
'Greenwich Standard Time' => 'Atlantic/Reykjavik',
'Sao Tome Standard Time' => 'Africa/Sao_Tome',
'Morocco Standard Time' => 'Africa/Casablanca',
'W. Europe Standard Time' => 'Europe/Berlin',
'Central Europe Standard Time' => 'Europe/Budapest',
'Romance Standard Time' => 'Europe/Paris',
'Central European Standard Time' => 'Europe/Warsaw',
'W. Central Africa Standard Time' => 'Africa/Lagos',
'Jordan Standard Time' => 'Asia/Amman',
'GTB Standard Time' => 'Europe/Bucharest',
'Middle East Standard Time' => 'Asia/Beirut',
'Egypt Standard Time' => 'Africa/Cairo',
'E. Europe Standard Time' => 'Europe/Chisinau',
'Syria Standard Time' => 'Asia/Damascus',
'West Bank Standard Time' => 'Asia/Hebron',
'South Africa Standard Time' => 'Africa/Johannesburg',
'FLE Standard Time' => 'Europe/Kiev',
'Israel Standard Time' => 'Asia/Jerusalem',
'Kaliningrad Standard Time' => 'Europe/Kaliningrad',
'Sudan Standard Time' => 'Africa/Khartoum',
'Libya Standard Time' => 'Africa/Tripoli',
'Namibia Standard Time' => 'Africa/Windhoek',
'Arabic Standard Time' => 'Asia/Baghdad',
'Turkey Standard Time' => 'Europe/Istanbul',
'Arab Standard Time' => 'Asia/Riyadh',
'Belarus Standard Time' => 'Europe/Minsk',
'Russian Standard Time' => 'Europe/Moscow',
'E. Africa Standard Time' => 'Africa/Nairobi',
'Iran Standard Time' => 'Asia/Tehran',
'Arabian Standard Time' => 'Asia/Dubai',
'Astrakhan Standard Time' => 'Europe/Astrakhan',
'Azerbaijan Standard Time' => 'Asia/Baku',
'Russia Time Zone 3' => 'Europe/Samara',
'Mauritius Standard Time' => 'Indian/Mauritius',
'Saratov Standard Time' => 'Europe/Saratov',
'Georgian Standard Time' => 'Asia/Tbilisi',
'Caucasus Standard Time' => 'Asia/Yerevan',
'Afghanistan Standard Time' => 'Asia/Kabul',
'West Asia Standard Time' => 'Asia/Tashkent',
'Ekaterinburg Standard Time' => 'Asia/Yekaterinburg',
'Pakistan Standard Time' => 'Asia/Karachi',
'India Standard Time' => 'Asia/Kolkata',
'Sri Lanka Standard Time' => 'Asia/Colombo',
'Nepal Standard Time' => 'Asia/Kathmandu',
'Central Asia Standard Time' => 'Asia/Almaty',
'Bangladesh Standard Time' => 'Asia/Dhaka',
'Omsk Standard Time' => 'Asia/Omsk',
'Myanmar Standard Time' => 'Asia/Yangon',
'SE Asia Standard Time' => 'Asia/Bangkok',
'Altai Standard Time' => 'Asia/Barnaul',
'W. Mongolia Standard Time' => 'Asia/Hovd',
'North Asia Standard Time' => 'Asia/Krasnoyarsk',
'N. Central Asia Standard Time' => 'Asia/Novosibirsk',
'Tomsk Standard Time' => 'Asia/Tomsk',
'China Standard Time' => 'Asia/Shanghai',
'North Asia East Standard Time' => 'Asia/Irkutsk',
'Singapore Standard Time' => 'Asia/Singapore',
'W. Australia Standard Time' => 'Australia/Perth',
'Taipei Standard Time' => 'Asia/Taipei',
'Ulaanbaatar Standard Time' => 'Asia/Ulaanbaatar',
'North Korea Standard Time' => 'Asia/Pyongyang',
'Aus Central W. Standard Time' => 'Australia/Eucla',
'Transbaikal Standard Time' => 'Asia/Chita',
'Tokyo Standard Time' => 'Asia/Tokyo',
'Korea Standard Time' => 'Asia/Seoul',
'Yakutsk Standard Time' => 'Asia/Yakutsk',
'Cen. Australia Standard Time' => 'Australia/Adelaide',
'AUS Central Standard Time' => 'Australia/Darwin',
'E. Australia Standard Time' => 'Australia/Brisbane',
'AUS Eastern Standard Time' => 'Australia/Sydney',
'West Pacific Standard Time' => 'Pacific/Port_Moresby',
'Tasmania Standard Time' => 'Australia/Hobart',
'Vladivostok Standard Time' => 'Asia/Vladivostok',
'Lord Howe Standard Time' => 'Australia/Lord_Howe',
'Bougainville Standard Time' => 'Pacific/Bougainville',
'Russia Time Zone 10' => 'Asia/Srednekolymsk',
'Magadan Standard Time' => 'Asia/Magadan',
'Norfolk Standard Time' => 'Pacific/Norfolk',
'Sakhalin Standard Time' => 'Asia/Sakhalin',
'Central Pacific Standard Time' => 'Pacific/Guadalcanal',
'Russia Time Zone 11' => 'Asia/Kamchatka',
'New Zealand Standard Time' => 'Pacific/Auckland',
'UTC+12' => 'Etc/GMT-12',
'Fiji Standard Time' => 'Pacific/Fiji',
'Kamchatka Standard Time' => 'Asia/Kamchatka',
'Chatham Islands Standard Time' => 'Pacific/Chatham',
'UTC+13' => 'Etc/GMT-13',
'Tonga Standard Time' => 'Pacific/Tongatapu',
'Samoa Standard Time' => 'Pacific/Apia',
'Line Islands Standard Time' => 'Pacific/Kiritimati',
];

private array $nix = [
'ACDT' => 'Australia/Adelaide',
'ACST' => 'Australia/Darwin',
'ACT' => 'Australia/Darwin',
'ACWST' => 'Australia/Eucla',
'ADT' => 'America/Halifax',
'AEDT' => 'Australia/Sydney',
'AEST' => 'Australia/Brisbane',
'AET' => 'Australia/Sydney',
'AFT' => 'Asia/Kabul',
'AKDT' => 'America/Anchorage',
'AKST' => 'America/Anchorage',
'ALMT' => 'Asia/Almaty',
'AMST' => 'America/Campo_Grande',
'AMT' => 'America/Campo_Grande',
'ANAST' => 'Asia/Anadyr',
'ANAT' => 'Asia/Anadyr',
'AQTT' => 'Asia/Aqtau',
'ART' => 'America/Argentina/Buenos_Aires',
'AST' => 'America/Halifax',
'AWDT' => 'Australia/Perth',
'AWST' => 'Australia/Perth',
'AZOST' => 'Atlantic/Azores',
'AZOT' => 'Atlantic/Azores',
'AZST' => 'Asia/Baku',
'AZT' => 'Asia/Baku',
'BNT' => 'Asia/Brunei',
'BIOT' => 'Indian/Chagos',
'BIT' => 'Pacific/Pago_Pago',
'BOT' => 'America/La_Paz',
'BRST' => 'America/Sao_Paulo',
'BRT' => 'America/Sao_Paulo',
'BST' => 'Europe/London',
'BTT' => 'Asia/Thimphu',
'CAT' => 'Africa/Maputo',
'CCT' => 'Indian/Cocos',
'CDT' => 'America/Chicago',
'CEST' => 'Europe/Berlin',
'CET' => 'Europe/Berlin',
'CHADT' => 'Pacific/Chatham',
'CHAST' => 'Pacific/Chatham',
'CHOT' => 'Asia/Choibalsan',
'CHOST' => 'Asia/Choibalsan',
'CHST' => 'Pacific/Guam',
'CHUT' => 'Pacific/Chuuk',
'CIST' => 'Pacific/Rarotonga',
'CIT' => 'Asia/Makassar',
'CKT' => 'Pacific/Rarotonga',
'CLST' => 'America/Santiago',
'CLT' => 'America/Santiago',
'COST' => 'America/Bogota',
'COT' => 'America/Bogota',
'CST' => 'America/Chicago',
'CT' => 'America/Chicago',
'CVT' => 'Atlantic/Cape_Verde',
'CWST' => 'Australia/Eucla',
'CXT' => 'Indian/Christmas',
'DAVT' => 'Antarctica/Davis',
'DDUT' => 'Antarctica/DumontDUrville',
'DFT' => 'Europe/Paris',
'EASST' => 'Pacific/Easter',
'EAST' => 'Pacific/Easter',
'EAT' => 'Africa/Nairobi',
'ECT' => 'Europe/Paris',
'EDT' => 'America/New_York',
'EEST' => 'Europe/Istanbul',
'EET' => 'Europe/Istanbul',
'EGST' => 'Atlantic/Reykjavik',
'EGT' => 'Atlantic/Reykjavik',
'EST' => 'America/New_York',
'ET' => 'America/New_York',
'FET' => 'Europe/Kaliningrad',
'FJT' => 'Pacific/Fiji',
'FKST' => 'Atlantic/Stanley',
'FKT' => 'Atlantic/Stanley',
'FNT' => 'America/Noronha',
'GALT' => 'Pacific/Galapagos',
'GAMT' => 'Pacific/Gambier',
'GET' => 'Asia/Tbilisi',
'GFT' => 'America/Cayenne',
'GILT' => 'Pacific/Tarawa',
'GMT' => 'Atlantic/Reykjavik',
'GST' => 'Asia/Dubai',
'GYT' => 'America/Guyana',
'HDT' => 'Pacific/Honolulu',
'HAEC' => 'Europe/Paris',
'HST' => 'Pacific/Honolulu',
'HKT' => 'Asia/Hong_Kong',
'HMT' => 'Asia/Kolkata',
'HOVT' => 'Asia/Hovd',
'ICT' => 'Asia/Bangkok',
'IDLW' => 'Pacific/Wake',
'IDT' => 'Asia/Jerusalem',
'IOT' => 'Indian/Chagos',
'IRDT' => 'Asia/Tehran',
'IRKT' => 'Asia/Irkutsk',
'IRST' => 'Asia/Tehran',
'IST' => 'Asia/Kolkata',
'JST' => 'Asia/Tokyo',
'KALT' => 'Europe/Kaliningrad',
'KGT' => 'Asia/Bishkek',
'KOST' => 'Pacific/Kosrae',
'KRAT' => 'Asia/Krasnoyarsk',
'KST' => 'Asia/Seoul',
'LHDT' => 'Australia/Lord_Howe',
'LINT' => 'Pacific/Kiritimati',
'MAGT' => 'Asia/Magadan',
'MART' => 'Pacific/Marquesas',
'MAWT' => 'Antarctica/Mawson',
'MDT' => 'America/Denver',
'MET' => 'Europe/Berlin',
'MEST' => 'Europe/Berlin',
'MHT' => 'Pacific/Kwajalein',
'MIST' => 'Antarctica/Macquarie',
'MIT' => 'Pacific/Apia',
'MMT' => 'Asia/Yangon',
'MSK' => 'Europe/Moscow',
'MST' => 'America/Denver',
'MUT' => 'Indian/Mauritius',
'MVT' => 'Indian/Maldives',
'MYT' => 'Asia/Kuala_Lumpur',
'NCT' => 'Pacific/Noumea',
'NDT' => 'America/St_Johns',
'NFT' => 'Pacific/Norfolk',
'NPT' => 'Asia/Kathmandu',
'NST' => 'America/St_Johns',
'NT' => 'America/St_Johns',
'NUT' => 'Pacific/Niue',
'NZDT' => 'Pacific/Auckland',
'NZST' => 'Pacific/Auckland',
'OMST' => 'Asia/Omsk',
'ORAT' => 'Asia/Oral',
'PDT' => 'America/Los_Angeles',
'PETT' => 'Asia/Kamchatka',
'PHOT' => 'Pacific/Enderbury',
'PHST' => 'Asia/Manila',
'PKT' => 'Asia/Karachi',
'PMDT' => 'America/Miquelon',
'PMST' => 'America/Miquelon',
'PONT' => 'Pacific/Pohnpei',
'PST' => 'America/Los_Angeles',
'PT' => 'America/Los_Angeles',
'PYST' => 'America/Asuncion',
'PYT' => 'America/Asuncion',
'RET' => 'Indian/Reunion',
'ROTT' => 'Antarctica/Rothera',
'SAKT' => 'Asia/Sakhalin',
'SAMT' => 'Europe/Samara',
'SAST' => 'Africa/Johannesburg',
'SBT' => 'Pacific/Guadalcanal',
'SCT' => 'Indian/Mahe',
'SGT' => 'Asia/Singapore',
'SLST' => 'Asia/Colombo',
'SRET' => 'Asia/Srednekolymsk',
'SRT' => 'America/Paramaribo',
'SST' => 'Pacific/Apia',
'SYOT' => 'Antarctica/Syowa',
'TAHT' => 'Pacific/Tahiti',
'THA' => 'Asia/Bangkok',
'TFT' => 'Indian/Kerguelen',
'TJT' => 'Asia/Dushanbe',
'TKT' => 'Pacific/Fakaofo',
'TLT' => 'Asia/Dili',
'TMT' => 'Asia/Ashgabat',
'TOT' => 'Pacific/Tongatapu',
'TVT' => 'Pacific/Funafuti',
'ULAST' => 'Asia/Ulaanbaatar',
'ULAT' => 'Asia/Ulaanbaatar',
'UYST' => 'America/Montevideo',
'UYT' => 'America/Montevideo',
'UZT' => 'Asia/Tashkent',
'VET' => 'America/Caracas',
'VLAT' => 'Asia/Vladivostok',
'VOLT' => 'Europe/Volgograd',
'VOST' => 'Antarctica/Vostok',
'VUT' => 'Pacific/Efate',
'WAKT' => 'Pacific/Wake',
'WAST' => 'Africa/Windhoek',
'WAT' => 'Africa/Lagos',
'WEST' => 'Europe/Lisbon',
'WET' => 'Europe/Lisbon',
'WIT' => 'Asia/Jayapura',
'WGST' => 'America/Godthab',
'WGT' => 'America/Godthab',
'WST' => 'Australia/Perth',
'YAKT' => 'Asia/Yakutsk',
'YEKT' => 'Asia/Yekaterinburg',
];

public function translateFromWindowsString(string $source): string
{
return $this->windows[$source] ?? 'UTC';
}

public function translateFromAbbreviatedString(string $source): string
{
return $this->nix[$source] ?? 'UTC';
}
}
14 changes: 14 additions & 0 deletions src/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Native\Laravel\Client\Client;
use Native\Laravel\DataObjects\Printer;
use Native\Laravel\Support\Timezones;

class System
{
Expand Down Expand Up @@ -56,4 +57,17 @@ public function printToPDF(string $html): string
'html' => $html,
])->json('result');
}

public function timezone(): string
{
$timezones = new Timezones();

if (PHP_OS_FAMILY === 'Windows') {
$timezone = $timezones->translateFromWindowsString(exec('tzutil /g'));
} else {
$timezone = $timezones->translateFromAbbreviatedString(exec('date +%Z'));
}

return $timezone;
}
}

0 comments on commit db818a8

Please sign in to comment.