Ticket #828 (closed defect: fixed)

Opened 14 months ago

Last modified 14 months ago

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) ($objDateTime->minute === false) ($objDateTime->second === 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.

Attachments

QDateTime.patch Download (1.1 KB) - added by michaelarnauts 14 months ago.
patch

Change History

Changed 14 months ago by michaelarnauts

patch

Changed 14 months ago by vakopian

  • status changed from new to in_QA
  • component changed from Other to Framework
  • milestone set to 2.1.1

Changed 14 months ago by vakopian

michaelarnauts, thanks for the solution and the patch. I've always found that check for ":" absurd, not just because of the example you provided, but also for e.g. localization etc.

Changed 14 months ago by vakopian

  • status changed from in_QA to closed
  • resolution set to fixed

(In [1468]) fixes #828

Note: See TracTickets for help on using tickets.