Source Code (Use browser search to find items of interest.)

Class Index

qt'QDate (./qt-2.1.0/src/tools/qdatetime.h:38)

class Q_EXPORT QDate
{
public:
    QDate()  { jd=0; }				// set null date
    QDate( int y, int m, int d );		// set date

    bool   isNull()	 const { return jd == 0; }
    bool   isValid()	 const;			// valid date

    int	   year()	 const;			// 1752..
    int	   month()	 const;			// 1..12
    int	   day()	 const;			// 1..31
    int	   dayOfWeek()	 const;			// 1..7 (monday==1)
    int	   dayOfYear()	 const;			// 1..365
    int	   daysInMonth() const;			// 28..31
    int	   daysInYear()	 const;			// 365 or 366

    virtual QString monthName( int month ) const;
    virtual QString dayName( int weekday ) const;

    QString toString()	 const;

    bool   setYMD( int y, int m, int d );

    QDate  addDays( int days )		const;
    int	   daysTo( const QDate & )	const;

    bool   operator==( const QDate &d ) const { return jd == d.jd; }
    bool   operator!=( const QDate &d ) const { return jd != d.jd; }
    bool   operator<( const QDate &d )	const { return jd < d.jd; }
    bool   operator<=( const QDate &d ) const { return jd <= d.jd; }
    bool   operator>( const QDate &d )	const { return jd > d.jd; }
    bool   operator>=( const QDate &d ) const { return jd >= d.jd; }

    static QDate currentDate();
    static bool	 isValid( int y, int m, int d );
    static bool	 leapYear( int year );

protected:
    static uint	 greg2jul( int y, int m, int d );
    static void	 jul2greg( uint jd, int &y, int &m, int &d );
private:
    static const char *monthNames[];
    static const char *weekdayNames[];
    uint	 jd;
    friend class QDateTime;
    friend Q_EXPORT QDataStream &operator<<( QDataStream &, const QDate & );
    friend Q_EXPORT QDataStream &operator>>( QDataStream &, QDate & );
};


/*****************************************************************************
  QTime class
 *****************************************************************************/


qt'QDate::QDate() (./qt-2.1.0/src/tools/qdatetime.cpp:143)

QDate::QDate( int y, int m, int d )
{
    setYMD( y, m, d );
}


/*!
  \fn bool QDate::isNull() const

  Returns TRUE if the date is null.  A null date is invalid.

  \sa isValid()
*/


/*!
  Returns TRUE if this date is valid.

  \sa isNull()
*/


qt'QDate::isValid() (./qt-2.1.0/src/tools/qdatetime.cpp:164)

bool QDate::isValid() const
{
    return jd >= FIRST_DAY;
}


/*!
  Returns the year (>= 1752) of this date.

  \sa month(), day()
*/


qt'QDate::year() (./qt-2.1.0/src/tools/qdatetime.cpp:176)

int QDate::year() const
{
    int y, m, d;
    jul2greg( jd, y, m, d );
    return y;
}

/*!
  Returns the month (January=1 .. December=12) of this date.

  \sa year(), day()
*/


qt'QDate::month() (./qt-2.1.0/src/tools/qdatetime.cpp:189)

int QDate::month() const
{
    int y, m, d;
    jul2greg( jd, y, m, d );
    return m;
}

/*!
  Returns the day of the month (1..31) of this date.

  \sa year(), month(), dayOfWeek()
*/


qt'QDate::day() (./qt-2.1.0/src/tools/qdatetime.cpp:202)

int QDate::day() const
{
    int y, m, d;
    jul2greg( jd, y, m, d );
    return d;
}

/*!
  Returns the weekday (Monday=1 .. Sunday=7) for this date.

  \sa day(), dayOfYear()
*/


qt'QDate::dayOfWeek() (./qt-2.1.0/src/tools/qdatetime.cpp:215)

int QDate::dayOfWeek() const
{
    return (((jd+1) % 7) + 6)%7 + 1;
}

/*!
  Returns the day of the year (1..365) for this date.

  \sa day(), dayOfWeek()
*/


qt'QDate::dayOfYear() (./qt-2.1.0/src/tools/qdatetime.cpp:226)

int QDate::dayOfYear() const
{
    return jd - greg2jul(year(), 1, 1) + 1;
}

/*!
  Returns the number of days in the month (28..31) for this date.

  \sa day(), daysInYear()
*/


qt'QDate::daysInMonth() (./qt-2.1.0/src/tools/qdatetime.cpp:237)

int QDate::daysInMonth() const
{
    int y, m, d;
    jul2greg( jd, y, m, d );
    if ( m == 2 && leapYear(y) )
	return 29;
    else
	return monthDays[m];
}

/*!
  Returns the number of days in the year (365 or 366) for this date.

  \sa day(), daysInMonth()
*/


qt'QDate::daysInYear() (./qt-2.1.0/src/tools/qdatetime.cpp:253)

int QDate::daysInYear() const
{
    int y, m, d;
    jul2greg( jd, y, m, d );
    return leapYear(y) ? 366 : 365;
}


/*!
  Returns the name of the \a month.

  Month 1 == "Jan", month 2 == "Feb" etc.

  \sa toString(), dayName()
*/


qt'QDate::monthName() (./qt-2.1.0/src/tools/qdatetime.cpp:269)

QString QDate::monthName( int month ) const
{
#if defined(CHECK_RANGE)
    if ( month < 1 || month > 12 ) {
	qWarning( "QDate::monthName: Parameter out ouf range." );
	month = 1;
    }
#endif
    // ### Remove the fromLatin1 during localization
    return QString::fromLatin1(monthNames[month-1]);
}

/*!
  Returns the name of the \a weekday.

  Weekday 1 == "Mon", day 2 == "Tue" etc.

  \sa toString(), monthName()
*/


qt'QDate::dayName() (./qt-2.1.0/src/tools/qdatetime.cpp:289)

QString QDate::dayName( int weekday ) const
{
#if defined(CHECK_RANGE)
    if ( weekday < 1 || weekday > 7 ) {
	qWarning( "QDate::dayName: Parameter out of range." );
	weekday = 1;
    }
#endif
    // ### Remove the fromLatin1 during localization
    return QString::fromLatin1(weekdayNames[weekday-1]);
}


/*!
  Returns the date as a string.

  The string format is "Sat May 20 1995". This function uses the
  dayName() and monthName() functions to generate the string.

  \sa dayName(), monthName()
*/


qt'QDate::toString() (./qt-2.1.0/src/tools/qdatetime.cpp:311)

QString QDate::toString() const
{
    int y, m, d;
    jul2greg( jd, y, m, d );
    QString buf = dayName(dayOfWeek());
    buf += ' ';
    buf += monthName(m);
    QString t;
    t.sprintf( " %d %d", d, y);
    buf += t;
    return buf;
}


/*!
  Sets the year \a y, month \a m and day \a d.

  \a y must be in the range 1752-ca. 8000, \a m must be in the range
  1-12, and \a d must be in the range 1-31. Exception: if \a y is in
  the range 0-99, it is interpreted as 1900-1999.

  Returns TRUE if the date is valid, otherwise FALSE.
*/


qt'QDate::setYMD() (./qt-2.1.0/src/tools/qdatetime.cpp:335)

bool QDate::setYMD( int y, int m, int d )
{
    if ( !isValid(y,m,d) ) {
#if defined(CHECK_RANGE)
	 qWarning( "QDate::setYMD: Invalid date %04d/%02d/%02d", y, m, d );
#endif
	 return FALSE;
    }
    jd = greg2jul( y, m, d );
#if defined(DEBUG)
    ASSERT( year() == y && month() == m && day() == d );
#endif
    return TRUE;
}

/*!
  Returns a QDate object containing a date \a ndays later than the
  date of this object (or earlier if \a ndays is negative).

  \sa daysTo()
*/


qt'QDate::addDays() (./qt-2.1.0/src/tools/qdatetime.cpp:357)

QDate QDate::addDays( int ndays ) const
{
    QDate d;
    d.jd = jd + ndays;
    return d;
}

/*!
  Returns the number of days from this date to \a d (which is negative
  if \a d is earlier than this date).

  Example:
  \code
    QDate d1( 1995, 5, 17 );		// May 17th 1995
    QDate d2( 1995, 5, 20 );		// May 20th 1995
    d1.daysTo( d2 );			// returns 3
    d2.daysTo( d1 );			// returns -3
  \endcode

  \sa addDays()
*/


qt'QDate::daysTo() (./qt-2.1.0/src/tools/qdatetime.cpp:379)

int QDate::daysTo( const QDate &d ) const
{
    return d.jd - jd;
}


/*!
  \fn bool QDate::operator==( const QDate &d ) const
  Returns TRUE if this date is equal to \a d, or FALSE if
  they are different.
*/

/*!
  \fn bool QDate::operator!=( const QDate &d ) const
  Returns TRUE if this date is different from \a d, or FALSE if
  they are equal.
*/

/*!
  \fn bool QDate::operator<( const QDate &d ) const
  Returns TRUE if this date is earlier than \a d, otherwise FALSE.
*/

/*!
  \fn bool QDate::operator<=( const QDate &d ) const
  Returns TRUE if this date is earlier than or equal to \a d, otherwise FALSE.
*/

/*!
  \fn bool QDate::operator>( const QDate &d ) const
  Returns TRUE if this date is later than \a d, otherwise FALSE.
*/

/*!
  \fn bool QDate::operator>=( const QDate &d ) const
  Returns TRUE if this date is later than or equal to \a d, otherwise FALSE.
*/


/*!
  Returns the current date, as reported by the system clock.

  \sa QTime::currentTime(), QDateTime::currentDateTime()
*/


qt'QDate::currentDate() (./qt-2.1.0/src/tools/qdatetime.cpp:424)

QDate QDate::currentDate()
{
#if defined(_OS_WIN32_)

    SYSTEMTIME t;
    GetLocalTime( &t );
    QDate d;
    d.jd = greg2jul( t.wYear, t.wMonth, t.wDay );
    return d;

#else

    time_t ltime;
    time( <ime );
    tm *t = localtime( <ime );
    QDate d;
    d.jd = greg2jul( t->tm_year + 1900, t->tm_mon + 1, t->tm_mday );
    return d;

#endif
}

/*!
  Returns TRUE if the specified date (year \a y, month \a m and day \a
  d) is valid.

  Example:
  \code
    QDate::isValid( 2002, 5, 17 );	// TRUE;  May 17th 2002 is OK.
    QDate::isValid( 2002, 2, 30 );	// FALSE; Feb 30th does not exist
    QDate::isValid( 2004, 2, 29 );	// TRUE; 2004 is a leap year
    QDate::isValid( 1202, 6, 6 );	// FALSE; 1202 is pre-Gregorian
  \endcode

  Note that a \a y value in the range 00-99 is interpreted as
  1900-1999.

  \sa isNull(), setYMD()
*/


qt'QDate::isValid() (./qt-2.1.0/src/tools/qdatetime.cpp:464)

bool QDate::isValid( int y, int m, int d )
{
    if ( y >= 0 && y <= 99 )
	y += 1900;
    else if ( y < FIRST_YEAR || (y == FIRST_YEAR && (m < 9 ||
						    (m == 9 && d < 14))) )
	return FALSE;
    return (d > 0 && m > 0 && m <= 12) &&
	   (d <= monthDays[m] || (d == 29 && m == 2 && leapYear(y)));
}

/*!
  Returns TRUE if the specified year \a y is a leap year.
*/


qt'QDate::leapYear() (./qt-2.1.0/src/tools/qdatetime.cpp:479)

bool QDate::leapYear( int y )
{
    return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;
}

/*!
  \internal
  Converts a Gregorian date to a Julian day.
  This algorithm is taken from Communications of the ACM, Vol 6, No 8.
  \sa jul2greg()
*/


qt'QDate::greg2jul() (./qt-2.1.0/src/tools/qdatetime.cpp:491)

uint QDate::greg2jul( int y, int m, int d )
{
    uint c, ya;
    if ( y <= 99 )
	y += 1900;
    if ( m > 2 ) {
	m -= 3;
    } else {
	m += 9;
	y--;
    }
    c = y;					// NOTE: Sym C++ 6.0 bug
    c /= 100;
    ya = y - 100*c;
    return 1721119 + d + (146097*c)/4 + (1461*ya)/4 + (153*m+2)/5;
}

/*!
  \internal
  Converts a Julian day to a Gregorian date.
  This algorithm is taken from Communications of the ACM, Vol 6, No 8.
  \sa greg2jul()
*/


qt'QDate::jul2greg() (./qt-2.1.0/src/tools/qdatetime.cpp:515)

void QDate::jul2greg( uint jd, int &y, int &m, int &d )
{
    uint x;
    uint j = jd - 1721119;
    y = (j*4 - 1)/146097;
    j = j*4 - 146097*y - 1;
    x = j/4;
    j = (x*4 + 3) / 1461;
    y = 100*y + j;
    x = (x*4) + 3 - 1461*j;
    x = (x + 4)/4;
    m = (5*x - 3)/153;
    x = 5*x - 3 - 153*m;
    d = (x + 5)/5;
    if ( m < 10 ) {
	m += 3;
    } else {
	m -= 9;
	y++;
    }
}


/*****************************************************************************
  QTime member functions
 *****************************************************************************/

/*!
  \class QTime qdatetime.h

  \brief The QTime class provides clock time functions.

  \ingroup time

  A QTime object contains a clock time, i.e. a number of hours,
  minutes, seconds and milliseconds since midnight. It can read the
  current time from the system clock, and measure a span of elapsed
  time. It provides functions for comparing times and for manipulating
  a time by adding a number of (milli)seconds.

  QTime operates with 24-hour clock format; it has no concept of
  AM/PM. It operates with local time; it does not know anything about
  time zones or daylight savings time.

  A QTime object is typically created either by giving the number of
  hours, minutes, seconds, and milliseconds explicitly, or by using
  the static function currentTime(), which makes a QTime object which
  contains the system's clock time. Note that the accuracy depends on
  the accuracy of the underlying operating system; not all systems
  provide 1-millisecond accuracy.

  The hour(), minute(), second(), and msec() functions provide access
  to the number of hours, minutes, seconds, and milliseconds of the
  time. The same information is provided in textual format by the
  toString() function.

  QTime provides a full set of operators to compare two QTime
  objects. A time is considered smaller than another if it is earlier
  than the other.

  The time a given number of seconds or milliseconds later than a
  given time can be found using the addSecs() or addMSecs()
  functions. Correspondingly, the number of (milli)seconds between two
  times can be found using the secsTo() or msecsTo() functions.

  QTime can be used to measure a span of elapsed time using the
  start(), restart(), and elapsed() functions.

  \sa QDate, QDateTime
*/

/*!
  \fn QTime::QTime()

  Constructs the time 0 hours, minutes, seconds and milliseconds,
  i.e. 00:00:00.000 (midnight). This is a valid time.

  \sa isValid()
*/

/*!
  Constructs a time with hour \a h, minute \a m, seconds \a s and
  milliseconds \a ms.

  \a h must be in the range 0-23, \a m and \a s must be in the range
  0-59, and \a ms must be in the range 0-999.

  \sa isValid()
*/