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