KDateTime::currentUtcDateTime()

David Jarvie lists at astrojar.org.uk
Fri Jul 28 11:53:07 BST 2006


On Friday 28 Jul 206 10:08, Peter_Kümmel wrote:
>David Jarvie wrote:
>> On Thursday 27 Jul 2006 18:19, Peter Kümmel wrote:
>>> Peter Kümmel wrote:
>>>> Why could we not also use the unix code on windows?
>>>> No problem with compiling.
>> 
>> If the UNIX code works on Windows, fine. I simply copied from the way 
that 
>> QDateTime::currentDateTime() works, with suitable modification to fetch 
>> the UTC time rather than the local time. The Windows code is untested, 
but 
>> it's simple enough to be reasonably confident that it will work.
>> 
>>>> KDateTime KDateTime::currentUtcDateTime()
>>>> {
>>>> #ifdef Q_OS_WIN
>>>>     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
>>>> }
>>>>
>>>> Peter
>>>>
>>>>
>>> Shouldn't the windows specific code not be part of the KDateTime 
>> constructor?
>> 
>> The KDateTime constructor does not fetch the current time, so there is 
no 
>> reason why this code should be in the constructor.
>> 
>
>OK, so the windows code does too much, and we could remove it.

I'm not sure what you mean. Are you saying that we should use the UNIX 
code for Windows, i.e. delete the Windows-specific code and remove the 
#ifdef? If so, why does QDateTime::currentDateTime() use different code 
for UNIX and Windows?

--
David Jarvie.





More information about the kde-core-devel mailing list