Skip to content

Instantly share code, notes, and snippets.

@robske110
Created September 13, 2017 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robske110/da680a0d26c6305352b72b88ec439383 to your computer and use it in GitHub Desktop.
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.
<?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