Skip to content

Commit

Permalink
Trying to take into account the number of days in a month.
Browse files Browse the repository at this point in the history
  • Loading branch information
renan committed Nov 30, 2011
1 parent c653d83 commit 8568ac6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Cake/Test/Case/View/Helper/TimeHelperTest.php
Expand Up @@ -126,6 +126,18 @@ public function testTimeAgoInWords() {
$seconds = 0;
$relative_date = '';

// Trying to take into account the number of days in a month
$month = date('m') - $months;
if ($month <= 0) {
$month = $months % 12;
}
$time = mktime(0, 0, 0, $month, 1, date('y') - $years);
$diffDays = date('t') - date('t', $time);

if ($diffDays > 0 && date('j') - date('t', $time) - $days > 0 && $months > 0 && $weeks === 0) {
continue;
}

if ($years > 0) {
// years and months and days
$relative_date .= ($relative_date ? ', -' : '-') . $years . ' year' . ($years > 1 ? 's' : '');
Expand Down

0 comments on commit 8568ac6

Please sign in to comment.