-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
namespace morphos\English; | ||
|
||
use InvalidArgumentException; | ||
|
||
class TimeSpeller extends \morphos\TimeSpeller | ||
{ | ||
protected static $units = [ | ||
self::YEAR => 'year', | ||
self::MONTH => 'month', | ||
self::DAY => 'day', | ||
self::HOUR => 'hour', | ||
self::MINUTE => 'minute', | ||
self::SECOND => 'second', | ||
]; | ||
|
||
public static function spellUnit($count, $unit) | ||
{ | ||
if (!isset(self::$units[$unit])) { | ||
throw new InvalidArgumentException('Unknown time unit: '.$unit); | ||
} | ||
|
||
return $count.' '.NounPluralization::pluralize(self::$units[$unit], $count); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
namespace morphos\test\English; | ||
|
||
require __DIR__.'/../../vendor/autoload.php'; | ||
|
||
use DateInterval; | ||
use morphos\English\TimeSpeller; | ||
|
||
class TimeSpellerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @dataProvider intervalsProvider() | ||
*/ | ||
public function testSpellInterval($interval, $options, $result) | ||
{ | ||
$this->assertEquals($result, TimeSpeller::spellInterval(new DateInterval($interval), $options)); | ||
} | ||
|
||
public function intervalsProvider() | ||
{ | ||
return | ||
[ | ||
['P1Y5M10D', 0, '1 year 5 months 10 days'], | ||
['P10Y1MT5H', 0, '10 years 1 month 5 hours'], | ||
['P3DT1H2M', 0, '3 days 1 hour 2 minutes'], | ||
['P10MT40M30S', 0, '10 months 40 minutes 30 seconds'], | ||
['P1Y5M10D', TimeSpeller::SEPARATE, '1 year, 5 months and 10 days'], | ||
['P10Y1MT5H', TimeSpeller::DIRECTION, '10 years 1 month 5 hours ago'], | ||
['P3DT1H2M', TimeSpeller::SEPARATE | TimeSpeller::DIRECTION, '3 days, 1 hour and 2 minutes ago'], | ||
['P10MT40M30S', TimeSpeller::SEPARATE, '10 months, 40 minutes and 30 seconds'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider timeUnitsProvider() | ||
*/ | ||
public function testSpellUnit($value, $unit, $result) | ||
{ | ||
$this->assertEquals($result, TimeSpeller::spellUnit($value, $unit)); | ||
} | ||
|
||
public function timeUnitsProvider() | ||
{ | ||
return | ||
[ | ||
[5, TimeSpeller::YEAR, '5 years'], | ||
[5, TimeSpeller::MONTH, '5 months'], | ||
[5, TimeSpeller::HOUR, '5 hours'], | ||
[5, TimeSpeller::SECOND, '5 seconds'], | ||
]; | ||
} | ||
} |