[Qt-interest] Strange problem storing and retrieving and comparing QTime/QDataTime
Thiago Macieira
thiago at kde.org
Tue Nov 17 15:40:49 CET 2009
Em Terça-feira 17 Novembro 2009, às 12:55:57, você escreveu:
> timeSpec() on both returns 0 (Qt::LocalTime)
>
> converting both toTimeSpec(Qt::UTC), just for a try, and comparison again
> failed.
>
> However "converting" toTime_t(), actually made the test pass!
Now that's weird. The time_t value is basically the number of seconds since
Jan 1, 1970, 0:00 UTC. It's calculated by converting the QDateTime to UTC then
calculating the number of seconds:
static uint toTime_tHelper(const QDate &utcDate, const QTime &utcTime)
{
int days = QDate(1970, 1, 1).daysTo(utcDate);
int secs = QTime().secsTo(utcTime);
if (days < 0 || (days == 0 && secs < 0))
return uint(-1);
qlonglong retval = (qlonglong(days) * SECS_PER_DAY) + secs;
if (retval >= Q_INT64_C(0xFFFFFFFF))
return uint(-1);
return uint(retval);
}
Now, remember that QDateTime keeps the time precision in *milliseconds*,
whereas time_t has a resolution of seconds. My guess is your roundtrip through
the database discarded the millisecond component (your source was
file.lastModified(), which does have millisecond resolution).
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091117/190e15c9/attachment.bin
More information about the Qt-interest-old
mailing list