From 0fc06e51e5020b8959310682bade02f97653dc73 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 4 Oct 2018 14:51:24 +1300 Subject: [PATCH] FIX: Drop seconds from DBDatetime::Nice() to restore SS3 behaviour. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that the medium date format depends on locale, with en_NZ being resolutely numeric. I’ve updated the test to verify a couple of locales to make this more obvious. Fixes #8121 --- src/ORM/FieldType/DBDatetime.php | 2 +- tests/php/ORM/DBDatetimeTest.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ORM/FieldType/DBDatetime.php b/src/ORM/FieldType/DBDatetime.php index 74c688625..da39e4c09 100644 --- a/src/ORM/FieldType/DBDatetime.php +++ b/src/ORM/FieldType/DBDatetime.php @@ -223,7 +223,7 @@ class DBDatetime extends DBDate implements TemplateGlobalProvider * @param int $timeLength * @return IntlDateFormatter */ - public function getFormatter($dateLength = IntlDateFormatter::MEDIUM, $timeLength = IntlDateFormatter::MEDIUM) + public function getFormatter($dateLength = IntlDateFormatter::MEDIUM, $timeLength = IntlDateFormatter::SHORT) { return parent::getFormatter($dateLength, $timeLength); } diff --git a/tests/php/ORM/DBDatetimeTest.php b/tests/php/ORM/DBDatetimeTest.php index fd0bd91db..ed0a4f3d1 100644 --- a/tests/php/ORM/DBDatetimeTest.php +++ b/tests/php/ORM/DBDatetimeTest.php @@ -88,9 +88,14 @@ class DBDatetimeTest extends SapphireTest public function testNice() { - $date = DBDatetime::create_field('Datetime', '2001-12-31 22:10:59'); + $date = DBDatetime::create_field('Datetime', '2001-12-11 22:10:59'); + // note: Some localisation packages exclude the ',' in default medium format - $this->assertRegExp('#31/12/2001(,)? 10:10:59 PM#i', $date->Nice()); + i18n::set_locale('en_NZ'); + $this->assertRegExp('#11/12/2001(,)? 10:10 PM#i', $date->Nice()); + + i18n::set_locale('en_US'); + $this->assertRegExp('#Dec 11(,)? 2001(,)? 10:10 PM#i', $date->Nice()); } public function testDate()