KDateTime::currentUtcDateTime()
David Jarvie
lists at astrojar.org.uk
Mon Jul 31 01:02:47 BST 2006
On Sunday 30 Jul 2006 14:39, Peter_Kümmel wrote:
>David Jarvie wrote:
>> I am confused as to why you mention the
>> constructor at all.
>
>I was wrong with the ctor.
>
>But I wonder why on windows the date is set but not under unix.
>When you wanna use setTime_t only then the windows code is superfluous.
>But when the date should be set on Windows and Unix then it seems
>to me that the unix code is incomplete.
>
>The Qt code looks like this:
>
>QDateTime QDateTime::currentDateTime()
>{
>#if defined(Q_OS_WIN)
> QDate d;
> QTime t;
> SYSTEMTIME st;
> memset(&st, 0, sizeof(SYSTEMTIME));
> GetLocalTime(&st);
> d.jd = QDate::gregorianToJulian(st.wYear, st.wMonth, st.wDay);
> t.mds = MSECS_PER_HOUR * st.wHour + MSECS_PER_MIN * st.wMinute + 1000 * st.wSecond
> + st.wMilliseconds;
> return QDateTime(d, t);
>#else
> QDateTime dt;
> QTime t;
> dt.setDate(QDate::currentDate());
> t = QTime::currentTime();
> if (t.ds()
> dt.setDate(QDate::currentDate()); // fetch date again
> dt.setTime(t);
> return dt;
>#endif
>}
>
>and the kde code like this:
>
>KDateTime KDateTime::currentUtcDateTime()
>{
>#ifdef Q_OS_WIN
> SYSTEMTIME st;
> memset(&st, 0, sizeof(SYSTEMTIME));
> GetSystemTime(&st);
> return KDateTime(QDate(st.wYear, st.wMonth, st.wDay),
> QTime(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds),
> Spec(UTC));
>#else
> time_t t;
> ::time(&t);
> KDateTime result;
> result.setTime_t(static_cast(t));
> return result;
>#endif
>}
>
>
>You've reproduced the Windows code but not the unix one:
>Should there not also be a setDate(QDate::currentDate());
>in the kde code?
It calls KDateTime::setTime_t(), not QDateTime::setTime_t(). There is no reason to duplicate the code in KDateTime::setTime_t() here.
--
David Jarvie.
More information about the kde-core-devel
mailing list