mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX MSSQLDatabase returns strange formatted Datetime values, removed hacks from DateField and PopupDateTimeField and put it in DataObject::__construct() so that it fixes the problem at the source
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@78963 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
601672cdff
commit
26606fd01d
@ -256,6 +256,20 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove milliseconds from the datetime returned by MSSQL. If we don't do this, PHP will choke.
|
||||||
|
// TODO: As per the above PostgreSQLDatabase change, implement more elegantly
|
||||||
|
if(DB::getConn() instanceof MSSQLDatabase) {
|
||||||
|
$this->class = get_class($this);
|
||||||
|
foreach($record as $k => $v) {
|
||||||
|
// MSSQLDatabase::date() uses datetime for the data type for "Date" and "SSDatetime"
|
||||||
|
if($this->db($k) == 'Date' || $this->db($k) == 'SSDatetime') {
|
||||||
|
$meridiem = substr($v, strlen($v) - 2, strlen($v));
|
||||||
|
$v = substr($v, 0, strlen($v) - 6);
|
||||||
|
$record[$k] = date('Y-m-d H:i:s', strtotime($v . ' ' . $meridiem));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set $this->record to $record, but ignore NULLs
|
// Set $this->record to $record, but ignore NULLs
|
||||||
$this->record = array();
|
$this->record = array();
|
||||||
foreach($record as $k => $v) {
|
foreach($record as $k => $v) {
|
||||||
|
@ -20,18 +20,6 @@ class DateField extends TextField {
|
|||||||
public static $validation_enabled = true;
|
public static $validation_enabled = true;
|
||||||
|
|
||||||
function setValue($val) {
|
function setValue($val) {
|
||||||
if ($val) {
|
|
||||||
if (!is_array($val) ) { //&& strlen($val) == 26) {
|
|
||||||
|
|
||||||
$ampm = substr($val,strlen($val)-2,strlen($val));
|
|
||||||
if ($ampm == "PM") { //correct for pm offset when cutting off 12-hour clock format
|
|
||||||
$val = substr($val,0,strlen($val)-6)."PM";
|
|
||||||
} elseif ($ampm == "AM") {
|
|
||||||
$val = substr($val,0,strlen($val)-6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(is_string($val) && preg_match('/^([\d]{2,4})-([\d]{1,2})-([\d]{1,2})/', $val)) {
|
if(is_string($val) && preg_match('/^([\d]{2,4})-([\d]{1,2})-([\d]{1,2})/', $val)) {
|
||||||
$this->value = preg_replace('/^([\d]{2,4})-([\d]{1,2})-([\d]{1,2})/','\\3/\\2/\\1', $val);
|
$this->value = preg_replace('/^([\d]{2,4})-([\d]{1,2})-([\d]{1,2})/','\\3/\\2/\\1', $val);
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,18 +68,6 @@ HTML;
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setValue( $val ) {
|
function setValue( $val ) {
|
||||||
if ($val) {
|
|
||||||
if (!is_array($val) ) { //&& strlen($val) == 26) {
|
|
||||||
|
|
||||||
$ampm = substr($val,strlen($val)-2,strlen($val));
|
|
||||||
if ($ampm == "PM") { //correct for pm offset when cutting off 12-hour clock format
|
|
||||||
$val = substr($val,0,strlen($val)-6)."PM";
|
|
||||||
} elseif ($ampm == "AM") {
|
|
||||||
$val = substr($val,0,strlen($val)-6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( is_array( $val ) ) {
|
if( is_array( $val ) ) {
|
||||||
|
|
||||||
// 1) Date
|
// 1) Date
|
||||||
|
Loading…
Reference in New Issue
Block a user