KDateTime::currentUtcDateTime()

Nicolas Goutte nicolasg at snafu.de
Sat Jul 29 06:59:44 BST 2006


On Friday 28 July 2006 22:52, Nicolas Goutte wrote:
> On Friday 28 July 2006 12:53, David Jarvie wrote:
> > 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?
>
> I could image that Trolltech wants to avoid to use a Unix layer in Windows
> and prefers to use directly the Windows API.

>  I do not know if it has a specific issue here in QDateTime but for certain
> part of Qt code this means a difference, e.g. Unicode file names in QFile.

Thinking further, I have found one possible reason: using the Windows API 
avoids the year 2038 bug if time_t is 32 bit long.

>
> > --
> > David Jarvie.
>
> Have a nice day!

Have a nice day!




More information about the kde-core-devel mailing list