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.
This commit is contained in:
Damian Mooyman 2014-04-01 17:03:10 +13:00
parent f58fd7ea55
commit 84d8022b32
4 changed files with 6 additions and 4 deletions

View File

@ -169,7 +169,7 @@ class Date extends DBField {
}
$formatD = $member->getDateFormat();
$zendDate = new Zend_Date($this->getValue());
$zendDate = new Zend_Date($this->getValue(), 'y-MM-dd');
return $zendDate->toString($formatD);
}

View File

@ -112,7 +112,7 @@ class SS_Datetime extends Date implements TemplateGlobalProvider {
$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 File

@ -212,7 +212,8 @@ class DateTest extends SapphireTest {
$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 File

@ -162,11 +162,12 @@ class SS_DatetimeTest extends SapphireTest {
'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