Permalink
Browse files

added ordinal in View NumberHelper

  • Loading branch information...
ritesh-pandey committed Jul 23, 2015
1 parent fa54940 commit 283f89d63b41c10a65f290abf9d9298e918e6d18
Showing with 25 additions and 0 deletions.
  1. +20 −0 src/I18n/Number.php
  2. +5 −0 src/View/Helper/NumberHelper.php
View
@@ -15,6 +15,7 @@
namespace Cake\I18n;
use NumberFormatter;
use Locale;
/**
* Number helper library.
@@ -312,4 +313,23 @@ public static function formatter($options = [])
return $formatter;
}
/**
* Returns a formatted integer as an ordinal number string (e.g. 1st, 2nd, 3rd, 4th, [...])
*
* ### Options
*
* - `locale` - The locale name to use for parsing the number, e.g. fr_FR
*
* @param string $value An integer or integer string.
* @param array $options An array with options.
* @return string
*/
public static function ordinal($value, array $options = [])
{
$locale = isset($options['locale']) ? $options['locale'] : Locale::getDefault();
$formatter = new NumberFormatter($locale, NumberFormatter::ORDINAL);
return $formatter->format($value);
}
}
@@ -230,4 +230,9 @@ public function implementedEvents()
{
return [];
}
public function ordinal($value, $options = [])
{
return $this->_engine->ordinal($value);
}
}

0 comments on commit 283f89d

Please sign in to comment.