Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix RelativeTimeFormatter incorrectly formatting 'about a month ago'/…
…'in about a month'

Refs #8377
  • Loading branch information
chinpei215 committed Mar 1, 2016
1 parent 9f4b920 commit c12162d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/I18n/RelativeTimeFormatter.php
Expand Up @@ -152,6 +152,7 @@ public function timeAgoInWords(DatetimeInterface $time, array $options = [])
'hour' => __d('cake', 'about an hour ago'),
'day' => __d('cake', 'about a day ago'),
'week' => __d('cake', 'about a week ago'),
'month' => __d('cake', 'about a month ago'),
'year' => __d('cake', 'about a year ago')
];
return $relativeDate ? sprintf($options['relativeString'], $relativeDate) : $aboutAgo[$fWord];
Expand All @@ -167,6 +168,7 @@ public function timeAgoInWords(DatetimeInterface $time, array $options = [])
'hour' => __d('cake', 'in about an hour'),
'day' => __d('cake', 'in about a day'),
'week' => __d('cake', 'in about a week'),
'month' => __d('cake', 'in about a month'),
'year' => __d('cake', 'in about a year')
];
return $aboutIn[$fWord];
Expand Down
8 changes: 8 additions & 0 deletions tests/TestCase/I18n/TimeTest.php
Expand Up @@ -310,6 +310,10 @@ public function testTimeAgoInWordsAccuracy($class)
]);
$expected = 'in about a day';
$this->assertEquals($expected, $result);

$time = new $class('+20 days');
$result = $time->timeAgoInWords(['accuracy' => 'month']);
$this->assertEquals('in about a month', $result);
}

/**
Expand Down Expand Up @@ -390,6 +394,10 @@ public function testTimeAgoInWordsNegativeValues($class)
$time = new $class('-23 hours');
$result = $time->timeAgoInWords(['accuracy' => 'day']);
$this->assertEquals('about a day ago', $result);

$time = new $class('-20 days');
$result = $time->timeAgoInWords(['accuracy' => 'month']);
$this->assertEquals('about a month ago', $result);
}

/**
Expand Down

0 comments on commit c12162d

Please sign in to comment.