Skip to content

Commit

Permalink
make tests more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared King committed Jun 20, 2019
1 parent c0dca34 commit f031423
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Utility.php
Expand Up @@ -283,12 +283,17 @@ public static function timeAgo($timestamp, $full = false)
*
* @param int $timestamp timestamp
* @param bool $full true: time ago has every granularity, false: time ago has biggest granularity only
* @param int|null $currentTime
*
* @return string computed time until
*/
public static function timeUntil($timestamp, $full = false)
public static function timeUntil($timestamp, $full = false, $currentTime = null)
{
$now = new \DateTime();
if ($currentTime) {
$now->setTimestamp($currentTime);
}

$then = new \DateTime();
$then->setTimestamp($timestamp);

Expand Down
7 changes: 5 additions & 2 deletions tests/UtilityTest.php
Expand Up @@ -3,7 +3,7 @@
/**
* @author Jared King <j@jaredtking.com>
*
* @link http://jaredtking.com
* @see http://jaredtking.com
*
* @copyright 2015 Jared King
* @license MIT
Expand Down Expand Up @@ -180,7 +180,10 @@ public function testTimeUntil()
$this->assertEquals('1 month', Utility::timeUntil(strtotime('+1 month') + 60));
$this->assertEquals('1 year', Utility::timeUntil(strtotime('+ 1 year') + 60));

$this->assertEquals('1 day, 1 minute, 40 seconds', Utility::timeUntil(strtotime('+86500 seconds'), true));
$now = '1560999241';
$timestamp = '1561085741'; // 86500 seconds later

$this->assertEquals('1 day, 1 minute, 40 seconds', Utility::timeUntil($timestamp, true, $now));
}

public function testUnixToDb()
Expand Down

0 comments on commit f031423

Please sign in to comment.