QDateTime issue?

Login or register to post comments
2 replies [Last post]
wizard's picture
Offline
Joined: 11/30/2009

Hi folks!

I just want to share some experience with QDateTime I had. Recently I worked on some age calculations when picking birthday date with QDateTimePicker. It's not so important for my point, but I'll mention that on every change on QDateTimePicker, method is called and age recalculated. A shorted version of calculation:

// getting the date and time now
$now = new QDateTime(QDateTime::Now());
// selected value in QDateTimePicker
$bDay = QDateTimeTextBox::ParseForDateTimeValue($pckBirthDay->DateTime);

// calculating age
$age = $now->Difference($bd);
$years = $age->Years;
$months = $age->Months;

Let suppose that selected age in QDateTimePicker is exact 18 years (3/1/1993 and QDateTime::Now() is 3/1/2011).
First notice $months should be 216, and not 219 as it's calculated and I got.

I looked after Difference in QDateTime.class.php

public function Difference(QDateTime $dttDateTime) {
    $intDifference = $this->Timestamp - $dttDateTime->Timestamp;
    return new QDateTimeSpan($intDifference);
}

That lead me to GetTimearray() method in QDateTimeSpan.class.php, which is heavily using constants for seconds, minutes, hours, days, months and years defined on beginning of mentioned class QDateTimeSpan. There is a small comment above all constants saying that it is for 30 days per month interval. I suppose incorrect calculation of $month in this case is because that "30 days per month interval", but maybe I'm wrong. (Also I think $years calculations were sometimes incorrect.)

Anybody with similar experience?

Edit: Changed topic title

Offline
Joined: 03/31/2008

Sounds like a legitimate bug. Mind opening a ticket for it?

wizard's picture
Offline
Joined: 11/30/2009