Ticket #828 (closed defect: fixed)
QDateTime returns with TimeNull = true when passed a date in IsoCompressed (20120402082830)
| Reported by: | michaelarnauts | Owned by: | somebody |
|---|---|---|---|
| Priority: | important | Milestone: | 2.1.1 |
| Component: | Framework | Version: | 2.1.0 Stable |
| Keywords: | Cc: |
Description
$test = new QDateTime('20120402082830');
var_dump($test);
Returns:
object(QDateTime)#9 (6) {
["blnDateNull":protected]=>
bool(false)
["blnTimeNull":protected]=>
bool(true)
["strSerializedData":protected]=>
NULL
date?=>
string(19) "2012-04-02 08:28:30"
timezone_type?=>
int(3)
timezone?=>
string(15) "Europe/Brussels?"
}
This is incorrect. The problem lies in QDateTime.class.php around line 164:
if (strpos($mixValue, ':') !== false)
$this->blnTimeNull = false;
Ofcourse, the input doesn't contain a ':', so the TimeNull? will not be set to false.
I guess this block can be replaced with something similar like the check for the date above:
$this->blnTimeNull = ($objDateTime->hour === false)
Note we can't do !$objDateTime->hour since 00:00:00 can be a valid hour. The value of $objdateTime->hour will be false if there is no time filled in. Therefore, we also have to check with === instead of == (since 0 will be equal to false then).
This fixes this bug, I don't know if this has any side effects.
Attached is the patch.

