mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
f58fd7ea55
commit
84d8022b32
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user