Wallogit.com
2017 © Pedro Peláez
Change Log - 26/7/13 - Fixed typo in read me (thanks @davemfletcher), (*2)
Timegap as a time-passed or time-until helper that only shows relevant information. If something (such as a birthday) is 6 months away, do we really care about the seconds or minutes? I basically got sick of seeing things like:, (*3)
Your next appointment is in 1 year, 3 months, 2 weeks, 4 days, 11 hours, 21 minutes, 11 seconds, (*4)
That's pretty over exagerated, but you get the idea. Timegap is an attempt at solving this., (*5)
https://packagist.org/packages/khandieyea/timegap, (*6)
Let's say your birthday is in 10 days:, (*7)
$gap = Timegap::createThen('a datetime stamp or unix tick that is 10 days from now');
echo "Your birthday is in: ";
echo $gap->output('weeks, days, hours, minutes, seconds', 2);
At first, this will result in, (*8)
Your birthday is in: 1 week, 4 days, (*9)
As the gap closes say 6 days away, the 'weeks' will disappear and we will see hours, (*10)
Your birthday is in: 6 days, 4 hours, (*11)
Singular/plural words are taken care of, when your birthday is just over a day away, (*12)
Your birthday is in: 1 day, 8 hours, (*13)
As we get closer and there's less than 1 day to go, again day drops off and minutes appear, (*14)
Your birthday is in: 4 hours, 46 minutes, (*15)
And again, when under an hour to go, (*16)
Your birthday is in: 24 minutes, 11 seconds, (*17)
$gap = new Timegap::createThen('a datetime stamp or tick that is 11 hours away');
echo "Your taxi will arrive in: ";
echo $gap->output('hours, minutes, seconds');
echo "<br />That's in precisely ";
echo $gap->output('seconds');
Would give you something like, (*18)
Your taxi will arrive in: 10 hours, 59 minutes, 58 seconds, (*19)
That's in precisely 39598 seconds, (*20)