summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Petculescu <gxgpet@gmail.com>2016-10-20 20:03:38 +0200
committerGeorge Petculescu <gxgpet@gmail.com>2016-10-20 20:03:38 +0200
commit03a1eac3b7bed8ed6df59109364a3eebe3f1cceb (patch)
treedaace20d5d97648c12eab042d7224d51a963c5e1
parent4fe5e99f437fe79cc40cebd08277eb319d8a6095 (diff)
ordinal_format will accept only non-negative natural numbers and return original value on failure + docs update regarding this.
-rw-r--r--system/helpers/inflector_helper.php4
-rw-r--r--user_guide_src/source/helpers/inflector_helper.rst11
2 files changed, 8 insertions, 7 deletions
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index c71516564..04e178aec 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -286,9 +286,9 @@ if ( ! function_exists('ordinal_format'))
*/
function ordinal_format($number)
{
- if ( ! ctype_digit((string) $number) OR $number < 0)
+ if ( ! ctype_digit((string) $number) OR $number < 1)
{
- return FALSE;
+ return $number;
}
$last_digit = array(
diff --git a/user_guide_src/source/helpers/inflector_helper.rst b/user_guide_src/source/helpers/inflector_helper.rst
index 8a6ca7a92..76cce6f4d 100644
--- a/user_guide_src/source/helpers/inflector_helper.rst
+++ b/user_guide_src/source/helpers/inflector_helper.rst
@@ -97,15 +97,16 @@ The following functions are available:
.. php:function:: ordinal_format($number)
- :param int $number: natural number to be converted
- :returns: Ordinal numeral for given number or FALSE on failure
+ :param int $number: non-negative natural number to be converted
+ :returns: Ordinal numeral for given number or original value on failure
:rtype: string
- Returns the ordinal numeral (0th, 1st, 2nd, 3rd etc.) for a
- natural number. If the input is not a natural number, the
- function will return boolean FALSE. Examples::
+ Returns the ordinal numeral (1st, 2nd, 3rd etc.) for a
+ non-negative natural number. If the input is not a natural number
+ greater than 0, the function will return the original value. Examples::
echo ordinal_format(1); // Returns 1st
echo ordinal_format(3); // Returns 3rd
echo ordinal_format(21); // Returns 21st
echo ordinal_format(102); // Returns 102nd
+ echo ordinal_format(-5); // Invalid input, will return -5