Created
September 13, 2017 11:49
-
-
Save robske110/da680a0d26c6305352b72b88ec439383 to your computer and use it in GitHub Desktop.
A nerdy timer to count down the final minutes to an Apple event.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Just for fun | |
$appleEventTimer = new AppleEventTimer(strtotime("12 September 2017")); | |
$appleEventTimer->start(); | |
echo("AppleEventTimer> exit, APPLE EVENT IS NOW!\n"); | |
class AppleEventTimer{ | |
/** @var int */ | |
const APPLE_EVENT_TIME = 19; //h | |
/** @var int */ | |
private $appleEventTime; //UNIX TIMESTAMP (s) | |
/** @var bool */ | |
private $run = false; | |
/** @var int */ | |
private $currTick = 0; | |
function __construct(int $appleEventDate){ | |
$this->appleEventTime = $appleEventDate + self::APPLE_EVENT_TIME * 60 * 60; | |
} | |
function recursiveMainTick(){ | |
if(time() >= $this->appleEventTime){ | |
echo("AppleEventTimer> THE APPLE EVENT IS NOW!\n"); | |
$this->stop(); | |
return; | |
} | |
if(($this->currTick % 30) === 0){ //every 30 secs | |
$willBeInS = $this->appleEventTime - time(); | |
echo("AppleEventTimer> The Apple event will be in ".(($willBeInS / 60) % 100)."min(s) and ".($willBeInS % 60)."s!\n"); | |
} | |
$this->currTick++; | |
if($this->run){ | |
sleep(1); | |
$this->recursiveMainTick(); | |
} | |
} | |
function start(){ | |
$this->run = true; | |
$this->recursiveMainTick(); | |
} | |
function stop(){ | |
$this->run = false; | |
$this->currTick = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment