Browse files

allow textual datetime description as input for timestamp and reference

  • Loading branch information...
1 parent 594ad5a commit 4328758f28102db10b6fecb129b28baebf8669ea @akDeveloper akDeveloper committed Apr 19, 2012
Showing with 9 additions and 0 deletions.
  1. +3 −0 src/Date/HumanDiff.php
  2. +6 −0 tests/Date/HumanDiffTest.php
View
3 src/Date/HumanDiff.php
@@ -86,6 +86,9 @@ public function get($timestamp, $reference = null)
$reference = time();
}
+ $timestamp = is_numeric($timestamp) ? $timestamp : strtotime($timestamp);
+ $reference = is_numeric($reference) ? $reference : strtotime($reference);
+
$delta = $reference - $timestamp;
$len = count($this->formats);
View
6 tests/Date/HumanDiffTest.php
@@ -72,6 +72,12 @@ public function testGetYears()
$this->assertEquals('2 years ago', $this->dh->get(-86400 * 365 * 2, 0));
$this->assertEquals('11 years ago', $this->dh->get(time() - 86400 * 365 * 11));
}
+
+ public function testGetStringTimestamp()
+ {
+ $this->assertEquals('3 months ago', $this->dh->get('2012-02-01 00:00:00','2012-04-19 00:00:00'));
+ $this->assertEquals('4 months ago', $this->dh->get('2012-01-01','2012-04-19'));
+ }
}
?>

0 comments on commit 4328758

Please sign in to comment.