-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimezone_info.php
More file actions
48 lines (36 loc) · 1.16 KB
/
timezone_info.php
File metadata and controls
48 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require_once 'api/config.php';
$ianaTimezone = $_GET['timezone'] ?? '';
if (empty($ianaTimezone)) {
sendError('Timezone is required', 400);
}
try {
$jsonFile = __DIR__ . '/json/timezone.json';
if (!file_exists($jsonFile)) {
sendError('Timezone data file not found', 404);
}
$jsonContent = file_get_contents($jsonFile);
$data = json_decode($jsonContent, true);
if (!isset($data['timezones']) || !is_array($data['timezones'])) {
sendError('Invalid timezone data format', 500);
}
$timezoneFound = null;
foreach ($data['timezones'] as $timezone) {
if (isset($timezone['iana_timezone']) &&
$timezone['iana_timezone'] === $ianaTimezone) {
$timezoneFound = $timezone;
break;
}
}
if (!$timezoneFound) {
sendError('Timezone "' . $ianaTimezone . '" not found', 404);
}
$result = [
'success' => true,
'timezone' => $timezoneFound
];
sendSuccess($result);
} catch (Exception $e) {
sendError('Error: ' . $e->getMessage(), 500);
}
?>