summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2016-11-23 12:27:42 +0100
committerAndrey Andreev <narf@devilix.net>2016-11-23 12:27:42 +0100
commit820d9cdaac9a9c0371404ce82b60a26ed3ac938f (patch)
tree1806d3f7f729d5bdce2134f379d74c52b877c03e
parente49aa1f1cb63ad90d6c2d204439f538dcc282243 (diff)
Fix #4917
-rw-r--r--system/helpers/date_helper.php4
-rw-r--r--tests/codeigniter/helpers/date_helper_test.php8
-rw-r--r--user_guide_src/source/changelog.rst1
3 files changed, 11 insertions, 2 deletions
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index 5f1fcf07e..7f072acfa 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -529,9 +529,9 @@ if ( ! function_exists('nice_date'))
}
// Date Like: YYYYMMDD
- if (preg_match('/^(\d{2})\d{2}(\d{4})$/i', $bad_date, $matches))
+ if (preg_match('/^\d{8}$/i', $bad_date, $matches))
{
- return date($format, strtotime($matches[1].'/01/'.$matches[2]));
+ return DateTime::createFromFormat('Ymd', $bad_date)->format($format);
}
// Date Like: MM-DD-YYYY __or__ M-D-YYYY (or anything in between)
diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php
index c4f99a97c..8a3502280 100644
--- a/tests/codeigniter/helpers/date_helper_test.php
+++ b/tests/codeigniter/helpers/date_helper_test.php
@@ -10,6 +10,14 @@ class Date_helper_test extends CI_TestCase {
// ------------------------------------------------------------------------
+ public function test_nice_date()
+ {
+ $this->assertEquals('2016-11-01', nice_date('201611', 'Y-m-d'));
+ $this->assertEquals('2016-11-23', nice_date('20161123', 'Y-m-d'));
+ }
+
+ // ------------------------------------------------------------------------
+
public function test_now_local()
{
/*
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 36b5d51e4..fd3f668cf 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -17,6 +17,7 @@ Bug fixes for 3.1.3
- Fixed a bug (#4902) - :doc:`Image Manipulation Library <libraries/image_lib>` processing via ImageMagick didn't work.
- Fixed a bug (#4905) - :doc:`Loader Library <libraries/loader>` didn't take into account possible user-provided directory paths when loading helpers.
- Fixed a bug (#4916) - :doc:`Session Library <libraries/session>` with ``sess_match_ip`` enabled was unusable for IPv6 clients when using the 'database' driver on MySQL 5.7.5+.
+- Fixed a bug (#4917) - :doc:`Date Helper <helpers/date_helper>` function :php:func:`nice_date()` didn't handle YYYYMMDD inputs properly.
Version 3.1.2
=============