Add countdown logic

This commit is contained in:
Vencislav Atanasov 2024-10-25 00:09:41 +03:00
parent b28f8909f9
commit b0ea463d53
1 changed files with 16 additions and 4 deletions

View File

@ -4,9 +4,20 @@
<?php <?php
e_('about_event'); e_('about_event');
// countdown begin
$eventStartTimes = [
'2024' => '2024-11-02 10:00:00',
];
$blog_slug = get_blog_slug(); $blog_slug = get_blog_slug();
if ($blog_slug === '2024') { if (array_key_exists($blog_slug, $eventStartTimes)) {
$now = new DateTimeImmutable('now');
$eventStart = new DateTimeImmutable($eventStartTimes[$blog_slug] . ' Europe/Sofia');
$interval = $now->diff($eventStart);
}
if ($interval instanceof DateInterval && $interval->invert === 0) {
?> ?>
<style> <style>
.countdown { .countdown {
@ -32,9 +43,9 @@ if ($blog_slug === '2024') {
<table> <table>
<tbody> <tbody>
<tr class="digits"> <tr class="digits">
<td>08</td> <td><?php echo $interval->format('%a'); ?></td>
<td>10</td> <td><?php echo $interval->format('%H'); ?></td>
<td>21</td> <td><?php echo $interval->format('%I'); ?></td>
</tr> </tr>
<tr class="units"> <tr class="units">
<td><?php e_('countdown_days'); ?></td> <td><?php e_('countdown_days'); ?></td>
@ -47,6 +58,7 @@ if ($blog_slug === '2024') {
</div> </div>
<?php <?php
} }
// countdown end
?> ?>
</section> </section>
<section class="content"> <section class="content">