From 662f581b24cead0ce323a8b1604666eb320a2b9c Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Sun, 5 Dec 2010 08:20:13 +0000 Subject: [PATCH] BUGFIX Fixed month conversion in DateField_View_JQuery::convert_iso_to_jquery_format() (fixes #6124, thanks mbren and natmchugh) (from r113247) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@114523 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/DateField.php | 10 ++++++++-- tests/forms/DatefieldViewJQueryTest.php | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/forms/DateField.php b/forms/DateField.php index 840644cd6..cf2acdd24 100755 --- a/forms/DateField.php +++ b/forms/DateField.php @@ -614,12 +614,18 @@ class DateField_View_JQuery { '/e/' => 'N', '/D/' => '', '/w/' => '', + // make single "M" lowercase '/([^M])M([^M])/' => '$1m$2', + // make single "M" at start of line lowercase '/^M([^M])/' => 'm$1', + // make single "M" at end of line lowercase '/([^M])M$/' => '$1m', + // match exactly three capital Ms not preceeded or followed by an M + '/(? 'M', + // match exactly two capital Ms not preceeded or followed by an M + '/(? 'mm', + // match four capital Ms (maximum allowed) '/MMMM/' => 'MM', - '/MMM/' => 'M', - '/MM/' => 'mm', '/l/' => '', '/YYYY/' => 'yy', '/yyyy/' => 'yy', diff --git a/tests/forms/DatefieldViewJQueryTest.php b/tests/forms/DatefieldViewJQueryTest.php index f0b0cd645..23b8a070a 100644 --- a/tests/forms/DatefieldViewJQueryTest.php +++ b/tests/forms/DatefieldViewJQueryTest.php @@ -16,9 +16,28 @@ class DateFieldViewJQueryTest extends SapphireTest { DateField_View_JQuery::convert_iso_to_jquery_format('d/MM/yyyy') ); + $this->assertEquals( + 'dd.m.yy', + DateField_View_JQuery::convert_iso_to_jquery_format('dd.M.yyyy'), + 'Month, no leading zero' + ); + $this->assertEquals( 'dd.mm.yy', - DateField_View_JQuery::convert_iso_to_jquery_format('dd.MM.yyyy') + DateField_View_JQuery::convert_iso_to_jquery_format('dd.MM.yyyy'), + 'Month, two digit' + ); + + $this->assertEquals( + 'dd.M.yy', + DateField_View_JQuery::convert_iso_to_jquery_format('dd.MMM.yyyy'), + 'Abbreviated month name' + ); + + $this->assertEquals( + 'dd.MM.yy', + DateField_View_JQuery::convert_iso_to_jquery_format('dd.MMMM.yyyy'), + 'Full month name' ); } } \ No newline at end of file