Skip to content

Instantly share code, notes, and snippets.

@neemzy neemzy/counter.php
Last active Jan 9, 2018

Embed
What would you like to do?
Counter to freedom
<?php
$naow = new DateTime(date('Y-m-d').' 00:00:00');
$last = new DateTime('2017-09-08 00:00:00'); // date of last working day
/**
* @param DateTime $date
*
* @return bool
*/
function isBusinessDay(DateTime $date)
{
if (in_array(
$date->format('Y-m-d'),
// exclude holidays
[
'2017-07-14',
'2017-08-15'
]
)) {
return false;
}
return $date->format('N') < 6;
}
function countBusinessDays(DateTime $start, DateTime $end)
{
$count = 0;
while (intval($start->format('Ymd')) <= intval($end->format('Ymd'))) {
if (isBusinessDay($start)) {
$count++;
}
$start->add(new DateInterval('P1D'));
}
return $count;
}
$days = countBusinessDays($naow, $last);
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>TPAN</title>
<style>
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-family: sans-serif;
}
body {
position: relative;
background: url('https://s-media-cache-ak0.pinimg.com/originals/69/36/60/693660ec438a3403b21cdaa0b68e78e9.jpg') no-repeat center center;
background-size: cover;
font-size: 2em;
}
.hero {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 500px;
height: 400px;
margin: auto;
background-color: rgba(255, 255, 255, 0.75);
text-align: center;
}
.counter {
font-size: 5em;
margin: 0.1em 0;
}
@keyframes colorz {
0% { color: red; }
16% { color: orange; }
32% { color: yellow; }
50% { color: green; }
66% { color: cornflowerblue; }
82% { color: purple; }
100% { color: magenta; }
}
.today {
line-height: 400px;
margin: 0;
font-size: 5em;
animation: colorz 1s infinite alternate;
}
</style>
</head>
<body>
<div class="hero">
<?php if (0 >= $days) { ?>
<p class="today">\o/</p>
<?php } else { ?>
<p>Hang in there! Only</p>
<p class="counter"><?= $days ?></p>
<p>day<?= $days > 1 ? 's' : '' ?> left!</p>
<?php } ?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.