-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimer.php
More file actions
67 lines (51 loc) · 2 KB
/
timer.php
File metadata and controls
67 lines (51 loc) · 2 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
header('Content-Type: application/json');
date_default_timezone_set('Asia/Manila');
$config = parse_ini_file('./admin/config.ini', true);
$content = "";
$electionTitle = $config['election_title'];
$electionEnded = $config['election_ended'];
$isAutoPilot = ($config['auto_pilot'] == 'true') ? 'true':'false';
$startDate = $config['start_date'] . ' ' . $config['start_time'];
$endDate = $config['end_date'] . ' ' . $config['end_time'];
$startDateTime = new DateTime($startDate);
$endDateTime = new DateTime($endDate);
$currentDateTime = new DateTime();
$timeToStart = $currentDateTime->diff($startDateTime);
$timeToEnd = $currentDateTime->diff($endDateTime);
$hoursToStart = $timeToStart->format('%h');
$hoursToEnd = $timeToEnd->format('%h');
$formattedTimeToStart = sprintf('%d hours %02d minutes %02d seconds',
$hoursToStart > 12 ? $hoursToStart - 12 : $hoursToStart,
$timeToStart->i,
$timeToStart->s
);
$formattedTimeToEnd = sprintf('%d days %d hours %02d minutes %02d seconds',
$timeToEnd->days,
$hoursToEnd > 12 ? $hoursToEnd - 12 : $hoursToEnd,
$timeToEnd->i,
$timeToEnd->s
);
$alreadyFinished = $currentDateTime > $endDateTime;
if($alreadyFinished){
$content = 'election_title = "' . $config['election_title'] . '"' . PHP_EOL;
$content .= 'start_date = ' . $config['start_date'] . PHP_EOL;
$content .= 'start_time = ' . $config['start_time'] . PHP_EOL;
$content .= 'end_date = ' . $config['end_date'] . PHP_EOL;
$content .= 'end_time = ' . $config['end_time'] . PHP_EOL;
$content .= 'auto_pilot = ' . $isAutoPilot . PHP_EOL;
$content .= 'election_ended = ' . 'true' . PHP_EOL;
file_put_contents('./admin/config.ini',$content);
$data = [
'election_title' => $electionTitle,
'election_status' => $electionEnded,
];
}else{
$data = [
'election_title' => $electionTitle,
'time_until_end' => $formattedTimeToEnd,
'alreadyFinished' => $alreadyFinished,
];
}
echo json_encode($data, JSON_PRETTY_PRINT);
?>