for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Phive Queue package.
*
* (c) Eugene Leonovich <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Phive\Queue;
abstract class QueueUtils
{
/**
* @param mixed $eta
* @return int The Unix timestamp.
* @throws \InvalidArgumentException
public static function normalizeEta($eta)
if (null === $eta) {
return time();
}
if (is_string($eta)) {
$eta = date_create($eta);
if ($eta instanceof \DateTime || $eta instanceof \DateTimeInterface) {
return $eta->getTimestamp();
if (is_int($eta)) {
return $eta;
throw new \InvalidArgumentException('The eta parameter is not valid.');
* @return int
public static function calculateDelay($eta)
return 0;
$delay = -time() + self::normalizeEta($eta);
return ($delay < 0) ? 0 : $delay;