Blame qtools/qdatetime.cpp

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