Blame qtools/qdatetime.cpp

Packit Service 50c9f2
/****************************************************************************
Packit Service 50c9f2
** 
Packit Service 50c9f2
**
Packit Service 50c9f2
** Implementation of date and time classes
Packit Service 50c9f2
**
Packit Service 50c9f2
** Created : 940124
Packit Service 50c9f2
**
Packit Service 50c9f2
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is part of the tools module of the Qt GUI Toolkit.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed under the terms of the Q Public License
Packit Service 50c9f2
** as defined by Trolltech AS of Norway and appearing in the file
Packit Service 50c9f2
** LICENSE.QPL included in the packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed and/or modified under the terms of the
Packit Service 50c9f2
** GNU General Public License version 2 as published by the Free Software
Packit Service 50c9f2
** Foundation and appearing in the file LICENSE.GPL included in the
Packit Service 50c9f2
** packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
Packit Service 50c9f2
** licenses may use this file in accordance with the Qt Commercial License
Packit Service 50c9f2
** Agreement provided with the Software.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
Packit Service 50c9f2
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit Service 50c9f2
**
Packit Service 50c9f2
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
Packit Service 50c9f2
**   information about Qt Commercial License Agreements.
Packit Service 50c9f2
** See http://www.trolltech.com/qpl/ for QPL licensing information.
Packit Service 50c9f2
** See http://www.trolltech.com/gpl/ for GPL licensing information.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Contact info@trolltech.com if any conditions of this licensing are
Packit Service 50c9f2
** not clear to you.
Packit Service 50c9f2
**
Packit Service 50c9f2
**********************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
#define gettimeofday	__hide_gettimeofday
Packit Service 50c9f2
#include "qdatetime.h"
Packit Service 50c9f2
#include "qdatastream.h"
Packit Service 50c9f2
#include <stdio.h>
Packit Service 50c9f2
#include <time.h>
Packit Service 50c9f2
#if defined(_OS_WIN32_)
Packit Service 50c9f2
#if defined(_CC_BOOL_DEF_)
Packit Service 50c9f2
#undef	bool
Packit Service 50c9f2
#include <windows.h>
Packit Service 50c9f2
#define bool int
Packit Service 50c9f2
#else
Packit Service 50c9f2
#include <windows.h>
Packit Service 50c9f2
#endif
Packit Service 50c9f2
#elif defined(_OS_MSDOS_)
Packit Service 50c9f2
#include <dos.h>
Packit Service 50c9f2
#elif defined(_OS_OS2_)
Packit Service 50c9f2
#include <os2.h>
Packit Service 50c9f2
#elif defined(_OS_UNIX_) || defined(_OS_MAC_)
Packit Service 50c9f2
#include <sys/time.h>
Packit Service 50c9f2
#include <unistd.h>
Packit Service 50c9f2
#undef	gettimeofday
Packit Service 50c9f2
extern "C" int gettimeofday( struct timeval *, struct timezone * );
Packit Service 50c9f2
#endif
Packit Service 50c9f2
Packit Service 50c9f2
static const uint FIRST_DAY	= 2361222;	// Julian day for 1752/09/14
Packit Service 50c9f2
static const int  FIRST_YEAR	= 1752;		// ### wrong for many countries
Packit Service 50c9f2
static const uint SECS_PER_DAY	= 86400;
Packit Service 50c9f2
static const uint MSECS_PER_DAY = 86400000;
Packit Service 50c9f2
static const uint SECS_PER_HOUR = 3600;
Packit Service 50c9f2
static const uint MSECS_PER_HOUR= 3600000;
Packit Service 50c9f2
static const uint SECS_PER_MIN	= 60;
Packit Service 50c9f2
static const uint MSECS_PER_MIN = 60000;
Packit Service 50c9f2
Packit Service 50c9f2
static const short monthDays[] ={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
Packit Service 50c9f2
Packit Service 50c9f2
// ##### Localize.
Packit Service 50c9f2
Packit Service 50c9f2
const char * const QDate::monthNames[] = {
Packit Service 50c9f2
    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
Packit Service 50c9f2
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
Packit Service 50c9f2
Packit Service 50c9f2
const char * const QDate::weekdayNames[] ={
Packit Service 50c9f2
    "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  QDate member functions
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
// REVISED: aavit
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \class QDate qdatetime.h
Packit Service 50c9f2
  \brief The QDate class provides date functions.
Packit Service 50c9f2
Packit Service 50c9f2
  \ingroup time
Packit Service 50c9f2
Packit Service 50c9f2
  A QDate object contains a calendar date, i.e. year, month, and day
Packit Service 50c9f2
  numbers in the modern western (Gregorian) calendar. It can read the
Packit Service 50c9f2
  current date from the system clock. It provides functions for
Packit Service 50c9f2
  comparing dates and for manipulating a date by adding a number of
Packit Service 50c9f2
  days.
Packit Service 50c9f2
Packit Service 50c9f2
  A QDate object is typically created either by giving the year, month
Packit Service 50c9f2
  and day numbers explicitly, or by using the static function
Packit Service 50c9f2
  currentDate(), which makes a QDate object which contains the
Packit Service 50c9f2
  system's clock date. An explicit date can also be set using
Packit Service 50c9f2
  setYMD().
Packit Service 50c9f2
Packit Service 50c9f2
  The year(), month(), and day() functions provide access to the year,
Packit Service 50c9f2
  month, and day numbers. Also, dayOfWeek() and dayOfYear() functions
Packit Service 50c9f2
  are provided. The same information is provided in textual format by
Packit Service 50c9f2
  the toString(), dayName(), and monthName() functions.
Packit Service 50c9f2
Packit Service 50c9f2
  QDate provides a full set of operators to compare two QDate
Packit Service 50c9f2
  objects. A date is considered smaller than another if it is earlier
Packit Service 50c9f2
  than the other.
Packit Service 50c9f2
Packit Service 50c9f2
  The date a given number of days later than a given date can be found
Packit Service 50c9f2
  using the addDays() function. Correspondingly, the number of days
Packit Service 50c9f2
  between two dates can be found using the daysTo() function.
Packit Service 50c9f2
Packit Service 50c9f2
  The daysInMonth() and daysInYear() functions tell how many days
Packit Service 50c9f2
  there are in this date's month and year, respectively. The
Packit Service 50c9f2
  isLeapYear() function tells whether this date is in a leap year.
Packit Service 50c9f2
Packit Service 50c9f2
  Note that QDate may not be used for date calculations for dates in
Packit Service 50c9f2
  the remote past, i.e. prior to the introduction of the Gregorian
Packit Service 50c9f2
  calendar. This calendar was adopted by England Sep. 14. 1752 (hence
Packit Service 50c9f2
  this is the earliest valid QDate), and subsequently by most other
Packit Service 50c9f2
  western countries, until 1923.
Packit Service 50c9f2
Packit Service 50c9f2
  The end of time is reached around 8000AD, by which time we expect Qt
Packit Service 50c9f2
  to be obsolete.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QTime, QDateTime
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDate::QDate()
Packit Service 50c9f2
  Constructs a null date. Null dates are invalid.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isNull(), isValid()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Constructs a date with the year \a y, month \a m and day \a d.
Packit Service 50c9f2
Packit Service 50c9f2
  \a y must be in the range 1752-ca. 8000, \a m must be in the range
Packit Service 50c9f2
  1-12, and \a d must be in the range 1-31. Exception: if \a y is in
Packit Service 50c9f2
  the range 0-99, it is interpreted as 1900-1999.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isValid()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDate::QDate( int y, int m, int d )
Packit Service 50c9f2
{
Packit Service 50c9f2
    jd = 0;
Packit Service 50c9f2
    setYMD( y, m, d );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QDate::isNull() const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if the date is null.  A null date is invalid.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isValid()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if this date is valid.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isNull()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QDate::isValid() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return jd >= FIRST_DAY;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the year (>= 1752) of this date.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa month(), day()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QDate::year() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    int y, m, d;
Packit Service 50c9f2
    jul2greg( jd, y, m, d );
Packit Service 50c9f2
    return y;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the month (January=1 .. December=12) of this date.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa year(), day()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QDate::month() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    int y, m, d;
Packit Service 50c9f2
    jul2greg( jd, y, m, d );
Packit Service 50c9f2
    return m;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the day of the month (1..31) of this date.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa year(), month(), dayOfWeek()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QDate::day() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    int y, m, d;
Packit Service 50c9f2
    jul2greg( jd, y, m, d );
Packit Service 50c9f2
    return d;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the weekday (Monday=1 .. Sunday=7) for this date.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa day(), dayOfYear()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QDate::dayOfWeek() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return (((jd+1) % 7) + 6)%7 + 1;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the day of the year (1..365) for this date.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa day(), dayOfWeek()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QDate::dayOfYear() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return jd - greg2jul(year(), 1, 1) + 1;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the number of days in the month (28..31) for this date.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa day(), daysInYear()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QDate::daysInMonth() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    int y, m, d;
Packit Service 50c9f2
    jul2greg( jd, y, m, d );
Packit Service 50c9f2
    if ( m == 2 && leapYear(y) )
Packit Service 50c9f2
	return 29;
Packit Service 50c9f2
    else
Packit Service 50c9f2
	return monthDays[m];
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the number of days in the year (365 or 366) for this date.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa day(), daysInMonth()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QDate::daysInYear() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    int y, m, d;
Packit Service 50c9f2
    jul2greg( jd, y, m, d );
Packit Service 50c9f2
    return leapYear(y) ? 366 : 365;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the name of the \a month.
Packit Service 50c9f2
Packit Service 50c9f2
  Month 1 == "Jan", month 2 == "Feb" etc.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa toString(), dayName()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QString QDate::monthName( int month ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
#if defined(CHECK_RANGE)
Packit Service 50c9f2
    if ( month < 1 || month > 12 ) {
Packit Service 50c9f2
	qWarning( "QDate::monthName: Parameter out ouf range." );
Packit Service 50c9f2
	month = 1;
Packit Service 50c9f2
    }
Packit Service 50c9f2
#endif
Packit Service 50c9f2
    // ### Remove the fromLatin1 during localization
Packit Service 50c9f2
    return QString::fromLatin1(monthNames[month-1]);
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the name of the \a weekday.
Packit Service 50c9f2
Packit Service 50c9f2
  Weekday 1 == "Mon", day 2 == "Tue" etc.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa toString(), monthName()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QString QDate::dayName( int weekday ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
#if defined(CHECK_RANGE)
Packit Service 50c9f2
    if ( weekday < 1 || weekday > 7 ) {
Packit Service 50c9f2
	qWarning( "QDate::dayName: Parameter out of range." );
Packit Service 50c9f2
	weekday = 1;
Packit Service 50c9f2
    }
Packit Service 50c9f2
#endif
Packit Service 50c9f2
    // ### Remove the fromLatin1 during localization
Packit Service 50c9f2
    return QString::fromLatin1(weekdayNames[weekday-1]);
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the date as a string.
Packit Service 50c9f2
Packit Service 50c9f2
  The string format is "Sat May 20 1995". This function uses the
Packit Service 50c9f2
  dayName() and monthName() functions to generate the string.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa dayName(), monthName()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QString QDate::toString() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    int y, m, d;
Packit Service 50c9f2
    jul2greg( jd, y, m, d );
Packit Service 50c9f2
    QString buf = dayName(dayOfWeek());
Packit Service 50c9f2
    buf += ' ';
Packit Service 50c9f2
    buf += monthName(m);
Packit Service 50c9f2
    QString t;
Packit Service 50c9f2
    t.sprintf( " %d %d", d, y);
Packit Service 50c9f2
    buf += t;
Packit Service 50c9f2
    return buf;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Sets the year \a y, month \a m and day \a d.
Packit Service 50c9f2
Packit Service 50c9f2
  \a y must be in the range 1752-ca. 8000, \a m must be in the range
Packit Service 50c9f2
  1-12, and \a d must be in the range 1-31. Exception: if \a y is in
Packit Service 50c9f2
  the range 0-99, it is interpreted as 1900-1999.
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if the date is valid, otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QDate::setYMD( int y, int m, int d )
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( !isValid(y,m,d) ) {
Packit Service 50c9f2
#if defined(CHECK_RANGE)
Packit Service 50c9f2
	 qWarning( "QDate::setYMD: Invalid date %04d/%02d/%02d", y, m, d );
Packit Service 50c9f2
#endif
Packit Service 50c9f2
	 return FALSE;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    jd = greg2jul( y, m, d );
Packit Service 50c9f2
#if defined(DEBUG)
Packit Service 50c9f2
    ASSERT( year() == (y > 99 ? y : 1900+y) && month() == m && day() == d );
Packit Service 50c9f2
#endif
Packit Service 50c9f2
    return TRUE;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns a QDate object containing a date \a ndays later than the
Packit Service 50c9f2
  date of this object (or earlier if \a ndays is negative).
Packit Service 50c9f2
Packit Service 50c9f2
  \sa daysTo()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDate QDate::addDays( int ndays ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    QDate d;
Packit Service 50c9f2
    d.jd = jd + ndays;
Packit Service 50c9f2
    return d;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the number of days from this date to \a d (which is negative
Packit Service 50c9f2
  if \a d is earlier than this date).
Packit Service 50c9f2
Packit Service 50c9f2
  Example:
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    QDate d1( 1995, 5, 17 );		// May 17th 1995
Packit Service 50c9f2
    QDate d2( 1995, 5, 20 );		// May 20th 1995
Packit Service 50c9f2
    d1.daysTo( d2 );			// returns 3
Packit Service 50c9f2
    d2.daysTo( d1 );			// returns -3
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  \sa addDays()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QDate::daysTo( const QDate &d ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return d.jd - jd;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QDate::operator==( const QDate &d ) const
Packit Service 50c9f2
  Returns TRUE if this date is equal to \a d, or FALSE if
Packit Service 50c9f2
  they are different.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QDate::operator!=( const QDate &d ) const
Packit Service 50c9f2
  Returns TRUE if this date is different from \a d, or FALSE if
Packit Service 50c9f2
  they are equal.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QDate::operator<( const QDate &d ) const
Packit Service 50c9f2
  Returns TRUE if this date is earlier than \a d, otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QDate::operator<=( const QDate &d ) const
Packit Service 50c9f2
  Returns TRUE if this date is earlier than or equal to \a d, otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QDate::operator>( const QDate &d ) const
Packit Service 50c9f2
  Returns TRUE if this date is later than \a d, otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QDate::operator>=( const QDate &d ) const
Packit Service 50c9f2
  Returns TRUE if this date is later than or equal to \a d, otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the current date, as reported by the system clock.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QTime::currentTime(), QDateTime::currentDateTime()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDate QDate::currentDate()
Packit Service 50c9f2
{
Packit Service 50c9f2
#if defined(_OS_WIN32_)
Packit Service 50c9f2
Packit Service 50c9f2
    SYSTEMTIME t;
Packit Service 50c9f2
    GetLocalTime( &t );
Packit Service 50c9f2
    QDate d;
Packit Service 50c9f2
    d.jd = greg2jul( t.wYear, t.wMonth, t.wDay );
Packit Service 50c9f2
    return d;
Packit Service 50c9f2
Packit Service 50c9f2
#else
Packit Service 50c9f2
Packit Service 50c9f2
    time_t ltime;
Packit Service 50c9f2
    time( &ltime );
Packit Service 50c9f2
    tm *t = localtime( &ltime );
Packit Service 50c9f2
    QDate d;
Packit Service 50c9f2
    d.jd = greg2jul( t->tm_year + 1900, t->tm_mon + 1, t->tm_mday );
Packit Service 50c9f2
    return d;
Packit Service 50c9f2
Packit Service 50c9f2
#endif
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if the specified date (year \a y, month \a m and day \a
Packit Service 50c9f2
  d) is valid.
Packit Service 50c9f2
Packit Service 50c9f2
  Example:
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    QDate::isValid( 2002, 5, 17 );	// TRUE;  May 17th 2002 is OK.
Packit Service 50c9f2
    QDate::isValid( 2002, 2, 30 );	// FALSE; Feb 30th does not exist
Packit Service 50c9f2
    QDate::isValid( 2004, 2, 29 );	// TRUE; 2004 is a leap year
Packit Service 50c9f2
    QDate::isValid( 1202, 6, 6 );	// FALSE; 1202 is pre-Gregorian
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  Note that a \a y value in the range 00-99 is interpreted as
Packit Service 50c9f2
  1900-1999.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isNull(), setYMD()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QDate::isValid( int y, int m, int d )
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( y >= 0 && y <= 99 )
Packit Service 50c9f2
	y += 1900;
Packit Service 50c9f2
    else if ( y < FIRST_YEAR || (y == FIRST_YEAR && (m < 9 ||
Packit Service 50c9f2
						    (m == 9 && d < 14))) )
Packit Service 50c9f2
	return FALSE;
Packit Service 50c9f2
    return (d > 0 && m > 0 && m <= 12) &&
Packit Service 50c9f2
	   (d <= monthDays[m] || (d == 29 && m == 2 && leapYear(y)));
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if the specified year \a y is a leap year.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QDate::leapYear( int y )
Packit Service 50c9f2
{
Packit Service 50c9f2
    return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \internal
Packit Service 50c9f2
  Converts a Gregorian date to a Julian day.
Packit Service 50c9f2
  This algorithm is taken from Communications of the ACM, Vol 6, No 8.
Packit Service 50c9f2
  \sa jul2greg()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
uint QDate::greg2jul( int y, int m, int d )
Packit Service 50c9f2
{
Packit Service 50c9f2
    uint c, ya;
Packit Service 50c9f2
    if ( y <= 99 )
Packit Service 50c9f2
	y += 1900;
Packit Service 50c9f2
    if ( m > 2 ) {
Packit Service 50c9f2
	m -= 3;
Packit Service 50c9f2
    } else {
Packit Service 50c9f2
	m += 9;
Packit Service 50c9f2
	y--;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    c = y;					// NOTE: Sym C++ 6.0 bug
Packit Service 50c9f2
    c /= 100;
Packit Service 50c9f2
    ya = y - 100*c;
Packit Service 50c9f2
    return 1721119 + d + (146097*c)/4 + (1461*ya)/4 + (153*m+2)/5;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \internal
Packit Service 50c9f2
  Converts a Julian day to a Gregorian date.
Packit Service 50c9f2
  This algorithm is taken from Communications of the ACM, Vol 6, No 8.
Packit Service 50c9f2
  \sa greg2jul()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QDate::jul2greg( uint jd, int &y, int &m, int &d )
Packit Service 50c9f2
{
Packit Service 50c9f2
    uint x;
Packit Service 50c9f2
    uint j = jd - 1721119;
Packit Service 50c9f2
    y = (j*4 - 1)/146097;
Packit Service 50c9f2
    j = j*4 - 146097*y - 1;
Packit Service 50c9f2
    x = j/4;
Packit Service 50c9f2
    j = (x*4 + 3) / 1461;
Packit Service 50c9f2
    y = 100*y + j;
Packit Service 50c9f2
    x = (x*4) + 3 - 1461*j;
Packit Service 50c9f2
    x = (x + 4)/4;
Packit Service 50c9f2
    m = (5*x - 3)/153;
Packit Service 50c9f2
    x = 5*x - 3 - 153*m;
Packit Service 50c9f2
    d = (x + 5)/5;
Packit Service 50c9f2
    if ( m < 10 ) {
Packit Service 50c9f2
	m += 3;
Packit Service 50c9f2
    } else {
Packit Service 50c9f2
	m -= 9;
Packit Service 50c9f2
	y++;
Packit Service 50c9f2
    }
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  QTime member functions
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \class QTime qdatetime.h
Packit Service 50c9f2
Packit Service 50c9f2
  \brief The QTime class provides clock time functions.
Packit Service 50c9f2
Packit Service 50c9f2
  \ingroup time
Packit Service 50c9f2
Packit Service 50c9f2
  A QTime object contains a clock time, i.e. a number of hours,
Packit Service 50c9f2
  minutes, seconds and milliseconds since midnight. It can read the
Packit Service 50c9f2
  current time from the system clock, and measure a span of elapsed
Packit Service 50c9f2
  time. It provides functions for comparing times and for manipulating
Packit Service 50c9f2
  a time by adding a number of (milli)seconds.
Packit Service 50c9f2
Packit Service 50c9f2
  QTime operates with 24-hour clock format; it has no concept of
Packit Service 50c9f2
  AM/PM. It operates with local time; it does not know anything about
Packit Service 50c9f2
  time zones or daylight savings time.
Packit Service 50c9f2
Packit Service 50c9f2
  A QTime object is typically created either by giving the number of
Packit Service 50c9f2
  hours, minutes, seconds, and milliseconds explicitly, or by using
Packit Service 50c9f2
  the static function currentTime(), which makes a QTime object which
Packit Service 50c9f2
  contains the system's clock time. Note that the accuracy depends on
Packit Service 50c9f2
  the accuracy of the underlying operating system; not all systems
Packit Service 50c9f2
  provide 1-millisecond accuracy.
Packit Service 50c9f2
Packit Service 50c9f2
  The hour(), minute(), second(), and msec() functions provide access
Packit Service 50c9f2
  to the number of hours, minutes, seconds, and milliseconds of the
Packit Service 50c9f2
  time. The same information is provided in textual format by the
Packit Service 50c9f2
  toString() function.
Packit Service 50c9f2
Packit Service 50c9f2
  QTime provides a full set of operators to compare two QTime
Packit Service 50c9f2
  objects. A time is considered smaller than another if it is earlier
Packit Service 50c9f2
  than the other.
Packit Service 50c9f2
Packit Service 50c9f2
  The time a given number of seconds or milliseconds later than a
Packit Service 50c9f2
  given time can be found using the addSecs() or addMSecs()
Packit Service 50c9f2
  functions. Correspondingly, the number of (milli)seconds between two
Packit Service 50c9f2
  times can be found using the secsTo() or msecsTo() functions.
Packit Service 50c9f2
Packit Service 50c9f2
  QTime can be used to measure a span of elapsed time using the
Packit Service 50c9f2
  start(), restart(), and elapsed() functions.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QDate, QDateTime
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QTime::QTime()
Packit Service 50c9f2
Packit Service 50c9f2
  Constructs the time 0 hours, minutes, seconds and milliseconds,
Packit Service 50c9f2
  i.e. 00:00:00.000 (midnight). This is a valid time.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isValid()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Constructs a time with hour \a h, minute \a m, seconds \a s and
Packit Service 50c9f2
  milliseconds \a ms.
Packit Service 50c9f2
Packit Service 50c9f2
  \a h must be in the range 0-23, \a m and \a s must be in the range
Packit Service 50c9f2
  0-59, and \a ms must be in the range 0-999.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isValid()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QTime::QTime( int h, int m, int s, int ms )
Packit Service 50c9f2
{
Packit Service 50c9f2
    setHMS( h, m, s, ms );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QTime::isNull() const
Packit Service 50c9f2
  Returns TRUE if the time is equal to 00:00:00.000. A null time is valid.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isValid()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if the time is valid, or FALSE if the time is invalid.
Packit Service 50c9f2
  The time 23:30:55.746 is valid, while 24:12:30 is invalid.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isNull()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QTime::isValid() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return ds < MSECS_PER_DAY;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the hour part (0..23) of the time.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QTime::hour() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return ds / MSECS_PER_HOUR;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the minute part (0..59) of the time.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QTime::minute() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return (ds % MSECS_PER_HOUR)/MSECS_PER_MIN;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the second part (0..59) of the time.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QTime::second() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return (ds / 1000)%SECS_PER_MIN;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the millisecond part (0..999) of the time.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QTime::msec() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return ds % 1000;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the time of this object in a textual format. Milliseconds
Packit Service 50c9f2
  are not included. The string format is HH:MM:SS, e.g. 1 second
Packit Service 50c9f2
  before midnight would be "23:59:59".
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QString QTime::toString() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    QString buf;
Packit Service 50c9f2
    buf.sprintf( "%.2d:%.2d:%.2d", hour(), minute(), second() );
Packit Service 50c9f2
    return buf;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Sets the time to hour \a h, minute \a m, seconds \a s and
Packit Service 50c9f2
  milliseconds \a ms.
Packit Service 50c9f2
Packit Service 50c9f2
  \a h must be in the range 0-23, \a m and \a s must be in the range
Packit Service 50c9f2
  0-59, and \a ms must be in the range 0-999. Returns TRUE if the set
Packit Service 50c9f2
  time is valid, otherwise FALSE.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isValid()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QTime::setHMS( int h, int m, int s, int ms )
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( !isValid(h,m,s,ms) ) {
Packit Service 50c9f2
#if defined(CHECK_RANGE)
Packit Service 50c9f2
	qWarning( "QTime::setHMS Invalid time %02d:%02d:%02d.%03d", h, m, s,
Packit Service 50c9f2
		 ms );
Packit Service 50c9f2
#endif
Packit Service 50c9f2
	ds = MSECS_PER_DAY;		// make this invalid
Packit Service 50c9f2
	return FALSE;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    ds = (h*SECS_PER_HOUR + m*SECS_PER_MIN + s)*1000 + ms;
Packit Service 50c9f2
    return TRUE;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns a QTime object containing a time \a nsecs seconds later than
Packit Service 50c9f2
  the time of this object (or earlier if \a ms is negative).
Packit Service 50c9f2
Packit Service 50c9f2
  Note that the time will wrap if it passes midnight.
Packit Service 50c9f2
Packit Service 50c9f2
  Example:
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    QTime n( 14, 0, 0 );                // n == 14:00:00
Packit Service 50c9f2
    QTime t;
Packit Service 50c9f2
    t = n.addSecs( 70 );                // t == 14:01:10
Packit Service 50c9f2
    t = n.addSecs( -70 );               // t == 13:58:50
Packit Service 50c9f2
    t = n.addSecs( 10*60*60 + 5 );      // t == 00:00:05
Packit Service 50c9f2
    t = n.addSecs( -15*60*60 );         // t == 23:00:00
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  \sa addMSecs(), secsTo(), QDateTime::addSecs()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QTime QTime::addSecs( int nsecs ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return addMSecs(nsecs*1000);
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the number of seconds from this time to \a t (which is
Packit Service 50c9f2
  negative if \a t is earlier than this time).
Packit Service 50c9f2
Packit Service 50c9f2
  Since QTime measures time within a day and there are 86400 seconds
Packit Service 50c9f2
  in a day, the result is between -86400 and 86400.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa addSecs() QDateTime::secsTo()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QTime::secsTo( const QTime &t ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return ((int)t.ds - (int)ds)/1000;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns a QTime object containing a time \a ms milliseconds later than
Packit Service 50c9f2
  the time of this object (or earlier if \a ms is negative).
Packit Service 50c9f2
Packit Service 50c9f2
  Note that the time will wrap if it passes midnight. See addSecs()
Packit Service 50c9f2
  for an example.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa addSecs(), msecsTo()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QTime QTime::addMSecs( int ms ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    QTime t;
Packit Service 50c9f2
    if ( ms < 0 ) {
Packit Service 50c9f2
	// % not well-defined for -ve, but / is.
Packit Service 50c9f2
	int negdays = (MSECS_PER_DAY-ms) / MSECS_PER_DAY;
Packit Service 50c9f2
	t.ds = ((int)ds + ms + negdays*MSECS_PER_DAY)
Packit Service 50c9f2
		% MSECS_PER_DAY;
Packit Service 50c9f2
    } else {
Packit Service 50c9f2
	t.ds = ((int)ds + ms) % MSECS_PER_DAY;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return t;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the number of milliseconds from this time to \a t (which is
Packit Service 50c9f2
  negative if \a t is earlier than this time).
Packit Service 50c9f2
Packit Service 50c9f2
  Since QTime measures time within a day and there are 86400000
Packit Service 50c9f2
  milliseconds in a day, the result is between -86400000 and 86400000.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa secsTo()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QTime::msecsTo( const QTime &t ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return (int)t.ds - (int)ds;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QTime::operator==( const QTime &t ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if this time is equal to \a t, or FALSE if they are
Packit Service 50c9f2
  different.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QTime::operator!=( const QTime &t ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if this time is different from \a t, or FALSE if they
Packit Service 50c9f2
  are equal.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QTime::operator<( const QTime &t ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if this time is earlier than \a t, otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QTime::operator<=( const QTime &t ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if this time is earlier than or equal to \a t,
Packit Service 50c9f2
  otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QTime::operator>( const QTime &t ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if this time is later than \a t, otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QTime::operator>=( const QTime &t ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if this time is later than or equal to \a t, otherwise
Packit Service 50c9f2
  FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the current time, as reported by the system clock.
Packit Service 50c9f2
Packit Service 50c9f2
  Note that the accuracy depends on the accuracy of the underlying
Packit Service 50c9f2
  operating system; not all systems provide 1-millisecond accuracy.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QTime QTime::currentTime()
Packit Service 50c9f2
{
Packit Service 50c9f2
    QTime ct;
Packit Service 50c9f2
    currentTime( &ct );
Packit Service 50c9f2
    return ct;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \internal
Packit Service 50c9f2
Packit Service 50c9f2
  Fetches the current time and returns TRUE if the time is within one
Packit Service 50c9f2
  minute after midnight, otherwise FALSE. The return value is used by
Packit Service 50c9f2
  QDateTime::currentDateTime() to ensure that the date there is correct.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QTime::currentTime( QTime *ct )
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( !ct ) {
Packit Service 50c9f2
#if defined(CHECK_NULL)
Packit Service 50c9f2
	qWarning( "QTime::currentTime(QTime *): Null pointer not allowed" );
Packit Service 50c9f2
#endif
Packit Service 50c9f2
	return FALSE;
Packit Service 50c9f2
    }
Packit Service 50c9f2
Packit Service 50c9f2
#if defined(_OS_WIN32_)
Packit Service 50c9f2
Packit Service 50c9f2
    SYSTEMTIME t;
Packit Service 50c9f2
    GetLocalTime( &t );
Packit Service 50c9f2
    ct->ds = MSECS_PER_HOUR*t.wHour + MSECS_PER_MIN*t.wMinute +
Packit Service 50c9f2
	     1000*t.wSecond + t.wMilliseconds;
Packit Service 50c9f2
    return (t.wHour == 0 && t.wMinute == 0);
Packit Service 50c9f2
Packit Service 50c9f2
#elif defined(_OS_OS2_)
Packit Service 50c9f2
Packit Service 50c9f2
    DATETIME t;
Packit Service 50c9f2
    DosGetDateTime( &t );
Packit Service 50c9f2
    ct->ds = MSECS_PER_HOUR*t.hours + MSECS_PER_MIN*t.minutes +
Packit Service 50c9f2
	     1000*t.seconds + 10*t.hundredths;
Packit Service 50c9f2
    return (t.hours == 0 && t.minutes == 0);
Packit Service 50c9f2
Packit Service 50c9f2
#elif defined(_OS_MSDOS_)
Packit Service 50c9f2
Packit Service 50c9f2
    _dostime_t t;
Packit Service 50c9f2
    _dos_gettime( &t );
Packit Service 50c9f2
    ct->ds = MSECS_PER_HOUR*t.hour + MSECS_PER_MIN*t.minute +
Packit Service 50c9f2
	     t.second*1000 + t.hsecond*10;
Packit Service 50c9f2
    return (t.hour== 0 && t.minute == 0);
Packit Service 50c9f2
Packit Service 50c9f2
#elif defined(_OS_UNIX_) || defined(_OS_MAC_)
Packit Service 50c9f2
Packit Service 50c9f2
    struct timeval tv;
Packit Service 50c9f2
    gettimeofday( &tv, 0 );
Packit Service 50c9f2
    time_t ltime = tv.tv_sec;
Packit Service 50c9f2
    tm *t = localtime( &ltime );
Packit Service 50c9f2
    ct->ds = (uint)( MSECS_PER_HOUR*t->tm_hour + MSECS_PER_MIN*t->tm_min +
Packit Service 50c9f2
		     1000*t->tm_sec + tv.tv_usec/1000 );
Packit Service 50c9f2
    return (t->tm_hour== 0 && t->tm_min == 0);
Packit Service 50c9f2
Packit Service 50c9f2
#else
Packit Service 50c9f2
Packit Service 50c9f2
    time_t ltime;			// no millisecond resolution!!
Packit Service 50c9f2
    ::time( &ltime );
Packit Service 50c9f2
    tm *t = localtime( &ltime );
Packit Service 50c9f2
    ct->ds = MSECS_PER_HOUR*t->tm_hour + MSECS_PER_MIN*t->tm_min +
Packit Service 50c9f2
	     1000*t->tm_sec;
Packit Service 50c9f2
    return (t->tm_hour== 0 && t->tm_min == 0);
Packit Service 50c9f2
#endif
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if the specified time is valid, otherwise FALSE.
Packit Service 50c9f2
Packit Service 50c9f2
  The time is valid if \a h is in the range 0-23, \a m and \a s are in
Packit Service 50c9f2
  the range 0-59, and \a ms is in the range 0-999.
Packit Service 50c9f2
Packit Service 50c9f2
  Example:
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    QTime::isValid(21, 10, 30);		// returns TRUE
Packit Service 50c9f2
    QTime::isValid(22, 5,  62);		// returns FALSE
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QTime::isValid( int h, int m, int s, int ms )
Packit Service 50c9f2
{
Packit Service 50c9f2
    return (uint)h < 24 && (uint)m < 60 && (uint)s < 60 && (uint)ms < 1000;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Sets this time to the current time. This is practical for timing:
Packit Service 50c9f2
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    QTime t;
Packit Service 50c9f2
    t.start();				// start clock
Packit Service 50c9f2
    ... // some lengthy task
Packit Service 50c9f2
    qDebug( "%d\n", t.elapsed() );	// prints # msecs elapsed
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  \sa restart(), elapsed(), currentTime()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QTime::start()
Packit Service 50c9f2
{
Packit Service 50c9f2
    *this = currentTime();
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Sets this time to the current time, and returns the number of
Packit Service 50c9f2
  milliseconds that have elapsed since the last time start() or
Packit Service 50c9f2
  restart() was called.
Packit Service 50c9f2
Packit Service 50c9f2
  This function is guaranteed to be atomic, and is thus very handy for
Packit Service 50c9f2
  repeated measurements: call start() to start the first measurement,
Packit Service 50c9f2
  then restart() for each later measurement.
Packit Service 50c9f2
Packit Service 50c9f2
  Note that the counter wraps to zero 24 hours after the last call to
Packit Service 50c9f2
  start() or restart().
Packit Service 50c9f2
Packit Service 50c9f2
  \warning If the system's clock setting has been changed since the
Packit Service 50c9f2
  last time start() or restart() was called, the result is undefined.
Packit Service 50c9f2
  This can happen e.g. when daylight saving is turned on or off.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa start(), elapsed(), currentTime()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QTime::restart()
Packit Service 50c9f2
{
Packit Service 50c9f2
    QTime t = currentTime();
Packit Service 50c9f2
    int n = msecsTo( t );
Packit Service 50c9f2
    if ( n < 0 )				// passed midnight
Packit Service 50c9f2
	n += 86400*1000;
Packit Service 50c9f2
    *this = t;
Packit Service 50c9f2
    return n;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the number of milliseconds that have elapsed since the last
Packit Service 50c9f2
  time start() or restart() was called.
Packit Service 50c9f2
Packit Service 50c9f2
  Note that the counter wraps to zero 24 hours after the last call to
Packit Service 50c9f2
  start() or restart.
Packit Service 50c9f2
Packit Service 50c9f2
  Note that the accuracy depends on the accuracy of the underlying
Packit Service 50c9f2
  operating system; not all systems provide 1-millisecond accuracy.
Packit Service 50c9f2
Packit Service 50c9f2
  \warning If the system's clock setting has been changed since the
Packit Service 50c9f2
  last time start() or restart() was called, the result is undefined.
Packit Service 50c9f2
  This can happen e.g. when daylight saving is turned on or off.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa start(), restart()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QTime::elapsed()
Packit Service 50c9f2
{
Packit Service 50c9f2
    int n = msecsTo( currentTime() );
Packit Service 50c9f2
    if ( n < 0 )				// passed midnight
Packit Service 50c9f2
	n += 86400*1000;
Packit Service 50c9f2
    return n;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  QDateTime member functions
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \class QDateTime qdatetime.h
Packit Service 50c9f2
  \brief The QDateTime class provides date and time functions.
Packit Service 50c9f2
Packit Service 50c9f2
  \ingroup time
Packit Service 50c9f2
Packit Service 50c9f2
  A QDateTime object contains a calendar date and a clock time (a
Packit Service 50c9f2
  "datetime"). It is a combination of the QDate and QTime classes. It
Packit Service 50c9f2
  can read the current datetime from the system clock. It provides
Packit Service 50c9f2
  functions for comparing datetimes and for manipulating a datetime by
Packit Service 50c9f2
  adding a number of seconds or days.
Packit Service 50c9f2
Packit Service 50c9f2
  A QDateTime object is typically created either by giving a date and
Packit Service 50c9f2
  time explicitly, or by using the static function currentTime(),
Packit Service 50c9f2
  which makes a QDateTime object which contains the system's clock
Packit Service 50c9f2
  time.
Packit Service 50c9f2
Packit Service 50c9f2
  The date() and time() functions provide access to the date and time
Packit Service 50c9f2
  parts of the datetime. The same information is provided in textual
Packit Service 50c9f2
  format by the toString() function.
Packit Service 50c9f2
Packit Service 50c9f2
  QDateTime provides a full set of operators to compare two QDateTime
Packit Service 50c9f2
  objects. A datetime is considered smaller than another if it is
Packit Service 50c9f2
  earlier than the other.
Packit Service 50c9f2
Packit Service 50c9f2
  The datetime a given number of days or seconds later than a given
Packit Service 50c9f2
  datetime can be found using the addDays() and addSecs()
Packit Service 50c9f2
  functions. Correspondingly, the number of days or seconds between
Packit Service 50c9f2
  two times can be found using the daysTo() or secsTo() functions.
Packit Service 50c9f2
Packit Service 50c9f2
  A datetime can also be set using the setTime_t() function, which
Packit Service 50c9f2
  takes a POSIX-standard "number of seconds since 00:00:00 on January
Packit Service 50c9f2
  1, 1970" value.
Packit Service 50c9f2
Packit Service 50c9f2
  The limitations regarding range and resolution mentioned in the
Packit Service 50c9f2
  QDate and QTime documentation apply for QDateTime also.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QDate, QTime
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDateTime::QDateTime()
Packit Service 50c9f2
Packit Service 50c9f2
  Constructs a null datetime (i.e. null date and null time).  A null
Packit Service 50c9f2
  datetime is invalid, since the date is invalid.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isValid()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Constructs a datetime with date \a date and null time (00:00:00.000).
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDateTime::QDateTime( const QDate &date )
Packit Service 50c9f2
    : d(date)
Packit Service 50c9f2
{
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Constructs a datetime with date \a date and time \a time.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDateTime::QDateTime( const QDate &date, const QTime &time )
Packit Service 50c9f2
    : d(date), t(time)
Packit Service 50c9f2
{
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QDateTime::isNull() const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if both the date and the time are null.	A null date is invalid.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QDate::isNull(), QTime::isNull()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QDateTime::isValid() const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if both the date and the time are valid.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QDate::isValid(), QTime::isValid()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDate QDateTime::date() const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the date part of this datetime.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa setDate(), time()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QTime QDateTime::time() const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the time part of this datetime.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa setTime(), date()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn void QDateTime::setDate( const QDate &date )
Packit Service 50c9f2
Packit Service 50c9f2
  Sets the date part of this datetime.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa date(), setTime()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn void QDateTime::setTime( const QTime &time )
Packit Service 50c9f2
Packit Service 50c9f2
  Sets the time part of this datetime.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa time(), setDate()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Sets the local date and time given the number of seconds that have passed
Packit Service 50c9f2
  since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
Packit Service 50c9f2
  On systems that do not support timezones this function will behave as if
Packit Service 50c9f2
  local time were UTC.
Packit Service 50c9f2
Packit Service 50c9f2
  Note that Microsoft Windows supports only a limited range of values for
Packit Service 50c9f2
  \a secsSince1Jan1970UTC.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QDateTime::setTime_t( uint secsSince1Jan1970UTC )
Packit Service 50c9f2
{
Packit Service 50c9f2
    time_t tmp = (time_t) secsSince1Jan1970UTC;
Packit Service 50c9f2
    tm *tM = localtime( &tmp );
Packit Service 50c9f2
    if ( !tM ) {
Packit Service 50c9f2
	tM = gmtime( &tmp );
Packit Service 50c9f2
	if ( !tM ) {
Packit Service 50c9f2
	    d.jd = QDate::greg2jul( 1970, 1, 1 );
Packit Service 50c9f2
	    t.ds = 0;
Packit Service 50c9f2
	    return;
Packit Service 50c9f2
	}
Packit Service 50c9f2
    }
Packit Service 50c9f2
    d.jd = QDate::greg2jul( tM->tm_year + 1900, tM->tm_mon + 1, tM->tm_mday );
Packit Service 50c9f2
    t.ds = MSECS_PER_HOUR*tM->tm_hour + MSECS_PER_MIN*tM->tm_min +
Packit Service 50c9f2
	    1000*tM->tm_sec;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Sets the UTC date and time given the number of seconds that have passed
Packit Service 50c9f2
  since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
Packit Service 50c9f2
Packit Service 50c9f2
  Note that Microsoft Windows supports only a limited range of values for
Packit Service 50c9f2
  \a secsSince1Jan1970UTC.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QDateTime::setTimeUtc_t( uint secsSince1Jan1970UTC )
Packit Service 50c9f2
{
Packit Service 50c9f2
    time_t tmp = (time_t) secsSince1Jan1970UTC;
Packit Service 50c9f2
    tm *tM = gmtime( &tmp );
Packit Service 50c9f2
    if ( !tM ) {
Packit Service 50c9f2
	    d.jd = QDate::greg2jul( 1970, 1, 1 );
Packit Service 50c9f2
	    t.ds = 0;
Packit Service 50c9f2
	    return;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    d.jd = QDate::greg2jul( tM->tm_year + 1900, tM->tm_mon + 1, tM->tm_mday );
Packit Service 50c9f2
    t.ds = MSECS_PER_HOUR*tM->tm_hour + MSECS_PER_MIN*tM->tm_min +
Packit Service 50c9f2
	    1000*tM->tm_sec;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the datetime as a string.
Packit Service 50c9f2
Packit Service 50c9f2
  The string format is "Sat May 20 03:40:13 1998".
Packit Service 50c9f2
Packit Service 50c9f2
  This function uses QDate::dayName(), QDate::monthName(), and
Packit Service 50c9f2
  QTime::toString() to generate the string.
Packit Service 50c9f2
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QString QDateTime::toString() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    QString buf = d.dayName(d.dayOfWeek());
Packit Service 50c9f2
    buf += ' ';
Packit Service 50c9f2
    buf += d.monthName(d.month());
Packit Service 50c9f2
    buf += ' ';
Packit Service 50c9f2
    buf += QString().setNum(d.day());
Packit Service 50c9f2
    buf += ' ';
Packit Service 50c9f2
    buf += t.toString();
Packit Service 50c9f2
    buf += ' ';
Packit Service 50c9f2
    buf += QString().setNum(d.year());
Packit Service 50c9f2
    return buf;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns a QDateTime object containing a datetime \a ndays days later
Packit Service 50c9f2
  than the datetime of this object (or earlier if \a ndays is
Packit Service 50c9f2
  negative).
Packit Service 50c9f2
Packit Service 50c9f2
  \sa daysTo(), addSecs()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDateTime QDateTime::addDays( int ndays ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return QDateTime( d.addDays(ndays), t );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns a QDateTime object containing a datetime \a nsecs seconds
Packit Service 50c9f2
  later than the datetime of this object (or earlier if \a nsecs is
Packit Service 50c9f2
  negative).
Packit Service 50c9f2
Packit Service 50c9f2
  \sa secsTo(), addDays()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDateTime QDateTime::addSecs( int nsecs ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    uint dd = d.jd;
Packit Service 50c9f2
    int  tt = t.ds;
Packit Service 50c9f2
    int  sign = 1;
Packit Service 50c9f2
    if ( nsecs < 0 ) {
Packit Service 50c9f2
	nsecs = -nsecs;
Packit Service 50c9f2
	sign = -1;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    if ( nsecs >= (int)SECS_PER_DAY ) {
Packit Service 50c9f2
	dd += sign*(nsecs/SECS_PER_DAY);
Packit Service 50c9f2
	nsecs %= SECS_PER_DAY;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    tt += sign*nsecs*1000;
Packit Service 50c9f2
    if ( tt < 0 ) {
Packit Service 50c9f2
	tt = MSECS_PER_DAY - tt - 1;
Packit Service 50c9f2
	dd -= tt / MSECS_PER_DAY;
Packit Service 50c9f2
	tt = tt % MSECS_PER_DAY;
Packit Service 50c9f2
	tt = MSECS_PER_DAY - tt - 1;
Packit Service 50c9f2
    } else if ( tt >= (int)MSECS_PER_DAY ) {
Packit Service 50c9f2
	dd += ( tt / MSECS_PER_DAY );
Packit Service 50c9f2
	tt = tt % MSECS_PER_DAY;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    QDateTime ret;
Packit Service 50c9f2
    ret.t.ds = tt;
Packit Service 50c9f2
    ret.d.jd = dd;
Packit Service 50c9f2
    return ret;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the number of days from this datetime to \a dt (which is
Packit Service 50c9f2
  negative if \a dt is earlier than this datetime).
Packit Service 50c9f2
Packit Service 50c9f2
  \sa addDays(), secsTo()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QDateTime::daysTo( const QDateTime &dt ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return d.daysTo( dt.d );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the number of seconds from this datetime to \a dt (which is
Packit Service 50c9f2
  negative if \a dt is earlier than this datetime).
Packit Service 50c9f2
Packit Service 50c9f2
  Example:
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    QDateTime dt = QDateTime::currentDateTime();
Packit Service 50c9f2
    QDateTime x( QDate(dt.year(),12,24), QTime(17,00) );
Packit Service 50c9f2
    qDebug( "There are %d seconds to Christmas", dt.secsTo(x) );
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  \sa addSecs(), daysTo(), QTime::secsTo()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QDateTime::secsTo( const QDateTime &dt ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return t.secsTo(dt.t) + d.daysTo(dt.d)*SECS_PER_DAY;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if this datetime is equal to \a dt, or FALSE if
Packit Service 50c9f2
  they are different.
Packit Service 50c9f2
  \sa operator!=()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QDateTime::operator==( const QDateTime &dt ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return  t == dt.t && d == dt.d;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if this datetime is different from \a dt, or FALSE if
Packit Service 50c9f2
  they are equal.
Packit Service 50c9f2
  \sa operator==()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QDateTime::operator!=( const QDateTime &dt ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return  t != dt.t || d != dt.d;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if this datetime is earlier than \a dt, otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QDateTime::operator<( const QDateTime &dt ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( d < dt.d )
Packit Service 50c9f2
	return TRUE;
Packit Service 50c9f2
    return d == dt.d ? t < dt.t : FALSE;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if this datetime is earlier than or equal to \a dt,
Packit Service 50c9f2
  otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QDateTime::operator<=( const QDateTime &dt ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( d < dt.d )
Packit Service 50c9f2
	return TRUE;
Packit Service 50c9f2
    return d == dt.d ? t <= dt.t : FALSE;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if this datetime is later than \a dt, otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QDateTime::operator>( const QDateTime &dt ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( d > dt.d )
Packit Service 50c9f2
	return TRUE;
Packit Service 50c9f2
    return d == dt.d ? t > dt.t : FALSE;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if this datetime is later than or equal to \a dt,
Packit Service 50c9f2
  otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QDateTime::operator>=( const QDateTime &dt ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( d > dt.d )
Packit Service 50c9f2
	return TRUE;
Packit Service 50c9f2
    return d == dt.d ? t >= dt.t : FALSE;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns the current datetime, as reported by the system clock.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QDate::currentDate(), QTime::currentTime()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDateTime QDateTime::currentDateTime()
Packit Service 50c9f2
{
Packit Service 50c9f2
    QDate cd = QDate::currentDate();
Packit Service 50c9f2
    QTime ct;
Packit Service 50c9f2
    if ( QTime::currentTime(&ct) )		// too close to midnight?
Packit Service 50c9f2
	cd = QDate::currentDate();		// YES! time for some midnight
Packit Service 50c9f2
						// voodoo, fetch date again
Packit Service 50c9f2
    return QDateTime( cd, ct );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  Date/time stream functions
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
#ifndef QT_NO_DATASTREAM
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \relates QDate
Packit Service 50c9f2
  Writes the date to the stream.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa \link datastreamformat.html Format of the QDataStream operators \endlink
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &operator<<( QDataStream &s, const QDate &d )
Packit Service 50c9f2
{
Packit Service 50c9f2
    return s << (Q_UINT32)(d.jd);
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \relates QDate
Packit Service 50c9f2
  Reads a date from the stream.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa \link datastreamformat.html Format of the QDataStream operators \endlink
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &operator>>( QDataStream &s, QDate &d )
Packit Service 50c9f2
{
Packit Service 50c9f2
    Q_UINT32 jd;
Packit Service 50c9f2
    s >> jd;
Packit Service 50c9f2
    d.jd = jd;
Packit Service 50c9f2
    return s;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \relates QTime
Packit Service 50c9f2
  Writes a time to the stream.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa \link datastreamformat.html Format of the QDataStream operators \endlink
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &operator<<( QDataStream &s, const QTime &t )
Packit Service 50c9f2
{
Packit Service 50c9f2
    return s << (Q_UINT32)(t.ds);
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \relates QTime
Packit Service 50c9f2
  Reads a time from the stream.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa \link datastreamformat.html Format of the QDataStream operators \endlink
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &operator>>( QDataStream &s, QTime &t )
Packit Service 50c9f2
{
Packit Service 50c9f2
    Q_UINT32 ds;
Packit Service 50c9f2
    s >> ds;
Packit Service 50c9f2
    t.ds = ds;
Packit Service 50c9f2
    return s;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \relates QDateTime
Packit Service 50c9f2
  Writes a datetime to the stream.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa \link datastreamformat.html Format of the QDataStream operators \endlink
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &operator<<( QDataStream &s, const QDateTime &dt )
Packit Service 50c9f2
{
Packit Service 50c9f2
    return s << dt.d << dt.t;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \relates QDateTime
Packit Service 50c9f2
  Reads a datetime from the stream.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa \link datastreamformat.html Format of the QDataStream operators \endlink
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &operator>>( QDataStream &s, QDateTime &dt )
Packit Service 50c9f2
{
Packit Service 50c9f2
    s >> dt.d >> dt.t;
Packit Service 50c9f2
    return s;
Packit Service 50c9f2
}
Packit Service 50c9f2
#endif //QT_NO_DATASTREAM