Skip to content

Commit

Permalink
Ensure single digits are still treated as numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan3dc committed Jul 24, 2017
1 parent 602b6ea commit 08bfbbd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ Changelog

--------

## 1.2.1 - 2017-07-24

### Added

* [Support] Add support for PHP 7.2

### Fixed

* [DateTime] Ensure single digits are treated as numbers by format().

--------

## 1.2.0 - 2017-03-05

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/Formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function format($format)
$return = $this->string($format);

# If the result looks like a number then return it as an int
if (preg_match("/^[1-9][0-9]+$/", $return)) {
if (preg_match("/^[1-9][0-9]*$/", $return)) {
# Only attempt to cast a number in the range supported by this install
if ($return < \PHP_INT_MAX) {
$return = (int) $return;
Expand Down
5 changes: 5 additions & 0 deletions tests/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public function testFormat4()
$date = DateTime::mktime(4, 22, 33, 1, 18, 2016);
$this->assertSame("042233", $date->format("His"));
}
public function testFormat5()
{
$date = DateTime::mktime(4, 22, 33, 1, 18, 2016);
$this->assertSame(1, $date->format("n"));
}
public function testNumeric()
{
$unix = time();
Expand Down

0 comments on commit 08bfbbd

Please sign in to comment.