Skip to content

Commit

Permalink
BUGFIX Fixed month conversion in DateField_View_JQuery::convert_iso_t…
Browse files Browse the repository at this point in the history
…o_jquery_format() (fixes #6124, thanks mbren and natmchugh)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@113247 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu authored and Sam Minnee committed Feb 2, 2011
1 parent 20b41e1 commit ac21b75
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 8 additions & 2 deletions forms/DateField.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,18 @@ static function convert_iso_to_jquery_format($format) {
'/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)MMM(?!M)/' => 'M',
// match exactly two capital Ms not preceeded or followed by an M
'/(?<!M)MM(?!M)/' => 'mm',
// match four capital Ms (maximum allowed)
'/MMMM/' => 'MM',
'/MMM/' => 'M',
'/MM/' => 'mm',
'/l/' => '',
'/YYYY/' => 'yy',
'/yyyy/' => 'yy',
Expand Down
21 changes: 20 additions & 1 deletion tests/forms/DatefieldViewJQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,28 @@ function testConvert() {
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'
);
}
}

0 comments on commit ac21b75

Please sign in to comment.