Skip to content
Browse files

BUG Fix Date and SS_DateTime::FormatFromSettings

This issue is caused by the odd default behaviour of Zend_Date, which attempts to parse yyyy-mm-dd format date and times as though they were yyyy-dd-mm.
  • Loading branch information...
1 parent f58fd7e commit 84d8022b326e3938753430678cfc3dfa50770d83 @tractorcow tractorcow committed
Showing with 6 additions and 4 deletions.
  1. +1 −1 model/fieldtypes/Date.php
  2. +1 −1 model/fieldtypes/Datetime.php
  3. +2 −1 tests/model/DateTest.php
  4. +2 −1 tests/model/DatetimeTest.php
View
2 model/fieldtypes/Date.php
@@ -169,7 +169,7 @@ public function FormatFromSettings($member = null) {
}
$formatD = $member->getDateFormat();
- $zendDate = new Zend_Date($this->getValue());
+ $zendDate = new Zend_Date($this->getValue(), 'y-MM-dd');
return $zendDate->toString($formatD);
}
View
2 model/fieldtypes/Datetime.php
@@ -112,7 +112,7 @@ public function FormatFromSettings($member = null) {
$formatD = $member->getDateFormat();
$formatT = $member->getTimeFormat();
- $zendDate = new Zend_Date($this->getValue());
+ $zendDate = new Zend_Date($this->getValue(), 'y-MM-dd HH:mm:ss');
return $zendDate->toString($formatD).' '.$zendDate->toString($formatT);
}
View
3 tests/model/DateTest.php
@@ -212,7 +212,8 @@ public function testFormatFromSettings() {
$fixtures = array(
'2000-12-31' => '31/12/2000',
'31-12-2000' => '31/12/2000',
- '31/12/2000' => '31/12/2000'
+ '31/12/2000' => '31/12/2000',
+ '2014-04-01' => '01/04/2014'
);
foreach($fixtures as $from => $to) {
View
3 tests/model/DatetimeTest.php
@@ -162,11 +162,12 @@ public function testFormatFromSettings() {
'2000-12-31 1:11:01' => '31/12/2000 01:11:01',
'12/12/2000 1:11:01' => '12/12/2000 01:11:01',
'2000-12-31' => '31/12/2000 12:00:00',
+ '2014-04-01 10:11:01' => '01/04/2014 10:11:01',
'10:11:01' => date('d/m/Y').' 10:11:01'
);
foreach($fixtures as $from => $to) {
- $date = DBField::create_field('Datetime', $from);
+ $date = DBField::create_field('SS_Datetime', $from);
// With member
$this->assertEquals($to, $date->FormatFromSettings($member));
// Without member

0 comments on commit 84d8022

Please sign in to comment.
Something went wrong with that request. Please try again.