1999-11-30 16:55:00 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/datetime.inl
|
|
|
|
// Purpose: definition of inline functions of wxDateTime and related
|
|
|
|
// classes declared in datetime.h
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Remarks: having the inline functions here allows us to minimize the
|
|
|
|
// dependencies (and hence the rebuild time) in debug builds.
|
|
|
|
// Modified by:
|
|
|
|
// Created: 30.11.99
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef INCLUDED_FROM_WX_DATETIME_H
|
|
|
|
#error "This file is only included by wx/datetime.h, don't include it manually!"
|
|
|
|
#endif
|
|
|
|
|
2000-01-02 18:17:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private macros
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-12-21 19:16:02 -05:00
|
|
|
#define MILLISECONDS_PER_DAY 86400000l
|
|
|
|
|
2000-01-02 18:17:55 -05:00
|
|
|
// some broken compilers (HP-UX CC) refuse to compile the "normal" version, but
|
|
|
|
// using a temp variable always might prevent other compilers from optimising
|
|
|
|
// it away - hence use of this ugly macro
|
|
|
|
#ifndef __HPUX__
|
|
|
|
#define MODIFY_AND_RETURN(op) return wxDateTime(*this).op
|
|
|
|
#else
|
|
|
|
#define MODIFY_AND_RETURN(op) wxDateTime dt(*this); dt.op; return dt
|
|
|
|
#endif
|
|
|
|
|
1999-11-30 16:55:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDateTime construction
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline bool wxDateTime::IsInStdRange() const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-20 20:44:45 -05:00
|
|
|
return m_time >= 0l && (m_time / TIME_T_FACTOR) < LONG_MAX;
|
1999-11-30 16:55:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::Now()
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-29 14:18:01 -05:00
|
|
|
return wxDateTime(*GetTmNow());
|
1999-11-30 16:55:00 -05:00
|
|
|
}
|
|
|
|
|
1999-12-20 20:44:45 -05:00
|
|
|
/* static */
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::Today()
|
1999-12-20 20:44:45 -05:00
|
|
|
{
|
2001-12-23 10:52:29 -05:00
|
|
|
struct tm *time = GetTmNow();
|
|
|
|
time->tm_hour = 0;
|
|
|
|
time->tm_min = 0;
|
|
|
|
time->tm_sec = 0;
|
1999-12-29 14:18:01 -05:00
|
|
|
|
2001-12-23 10:52:29 -05:00
|
|
|
return wxDateTime(*time);
|
1999-12-20 20:44:45 -05:00
|
|
|
}
|
|
|
|
|
2000-01-03 18:31:12 -05:00
|
|
|
#if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime& wxDateTime::Set(time_t timet)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
// assign first to avoid long multiplication overflow!
|
2001-02-08 16:13:12 -05:00
|
|
|
m_time = timet - WX_TIME_BASE_OFFSET ;
|
1999-11-30 16:55:00 -05:00
|
|
|
m_time *= TIME_T_FACTOR;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2000-01-03 18:31:12 -05:00
|
|
|
#endif
|
1999-11-30 16:55:00 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime& wxDateTime::SetToCurrent()
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
2000-01-24 08:27:37 -05:00
|
|
|
*this = Now();
|
|
|
|
return *this;
|
1999-11-30 16:55:00 -05:00
|
|
|
}
|
|
|
|
|
2000-01-03 18:31:12 -05:00
|
|
|
#if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime::wxDateTime(time_t timet)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
Set(timet);
|
|
|
|
}
|
2000-01-03 18:31:12 -05:00
|
|
|
#endif
|
1999-11-30 16:55:00 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime::wxDateTime(const struct tm& tm)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
Set(tm);
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime::wxDateTime(const Tm& tm)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
Set(tm);
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime::wxDateTime(double jdn)
|
1999-12-01 20:01:26 -05:00
|
|
|
{
|
|
|
|
Set(jdn);
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime& wxDateTime::Set(const Tm& tm)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
wxASSERT_MSG( tm.IsValid(), _T("invalid broken down date/time") );
|
|
|
|
|
|
|
|
return Set(tm.mday, (Month)tm.mon, tm.year, tm.hour, tm.min, tm.sec);
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime::wxDateTime(wxDateTime_t hour,
|
|
|
|
wxDateTime_t minute,
|
|
|
|
wxDateTime_t second,
|
|
|
|
wxDateTime_t millisec)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
Set(hour, minute, second, millisec);
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime::wxDateTime(wxDateTime_t day,
|
|
|
|
Month month,
|
|
|
|
int year,
|
|
|
|
wxDateTime_t hour,
|
|
|
|
wxDateTime_t minute,
|
|
|
|
wxDateTime_t second,
|
|
|
|
wxDateTime_t millisec)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
Set(day, month, year, hour, minute, second, millisec);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDateTime accessors
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxLongLong wxDateTime::GetValue() const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-20 20:44:45 -05:00
|
|
|
wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
|
1999-11-30 16:55:00 -05:00
|
|
|
|
|
|
|
return m_time;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline time_t wxDateTime::GetTicks() const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-20 20:44:45 -05:00
|
|
|
wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
|
1999-11-30 16:55:00 -05:00
|
|
|
if ( !IsInStdRange() )
|
|
|
|
{
|
|
|
|
return (time_t)-1;
|
|
|
|
}
|
|
|
|
|
2001-02-08 16:13:12 -05:00
|
|
|
return (time_t)((m_time / (long)TIME_T_FACTOR).GetLo())+WX_TIME_BASE_OFFSET ;
|
1999-11-30 16:55:00 -05:00
|
|
|
}
|
|
|
|
|
2001-04-08 18:32:17 -04:00
|
|
|
inline bool wxDateTime::SetToLastWeekDay(WeekDay weekday,
|
2000-07-15 15:51:35 -04:00
|
|
|
Month month,
|
|
|
|
int year)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
return SetToWeekDay(weekday, -1, month, year);
|
|
|
|
}
|
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
inline wxDateTime wxDateTime::GetWeekDayInSameWeek(WeekDay weekday,
|
|
|
|
WeekFlags flags) const
|
2000-01-02 18:17:55 -05:00
|
|
|
{
|
|
|
|
MODIFY_AND_RETURN( SetToWeekDayInSameWeek(weekday) );
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::GetNextWeekDay(WeekDay weekday) const
|
2000-01-02 18:17:55 -05:00
|
|
|
{
|
|
|
|
MODIFY_AND_RETURN( SetToNextWeekDay(weekday) );
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::GetPrevWeekDay(WeekDay weekday) const
|
2000-01-02 18:17:55 -05:00
|
|
|
{
|
|
|
|
MODIFY_AND_RETURN( SetToPrevWeekDay(weekday) );
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::GetWeekDay(WeekDay weekday,
|
|
|
|
int n,
|
|
|
|
Month month,
|
|
|
|
int year) const
|
2000-01-02 18:17:55 -05:00
|
|
|
{
|
|
|
|
wxDateTime dt(*this);
|
|
|
|
|
|
|
|
return dt.SetToWeekDay(weekday, n, month, year) ? dt : wxInvalidDateTime;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::GetLastWeekDay(WeekDay weekday,
|
|
|
|
Month month,
|
|
|
|
int year)
|
2000-01-02 18:17:55 -05:00
|
|
|
{
|
|
|
|
wxDateTime dt(*this);
|
|
|
|
|
|
|
|
return dt.SetToLastWeekDay(weekday, month, year) ? dt : wxInvalidDateTime;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::GetWeek(wxDateTime_t numWeek,
|
2002-12-04 09:11:26 -05:00
|
|
|
WeekDay weekday,
|
|
|
|
WeekFlags flags) const
|
2000-01-02 18:17:55 -05:00
|
|
|
{
|
|
|
|
wxDateTime dt(*this);
|
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
return dt.SetToTheWeek(numWeek, weekday, flags) ? dt : wxInvalidDateTime;
|
2000-01-02 18:17:55 -05:00
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::GetLastMonthDay(Month month, int year) const
|
2000-01-02 18:17:55 -05:00
|
|
|
{
|
|
|
|
MODIFY_AND_RETURN( SetToLastMonthDay(month, year) );
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::GetYearDay(wxDateTime_t yday) const
|
2000-01-02 18:17:55 -05:00
|
|
|
{
|
|
|
|
MODIFY_AND_RETURN( SetToYearDay(yday) );
|
|
|
|
}
|
|
|
|
|
1999-11-30 16:55:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDateTime comparison
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline bool wxDateTime::IsEqualTo(const wxDateTime& datetime) const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-20 20:44:45 -05:00
|
|
|
wxASSERT_MSG( IsValid() && datetime.IsValid(), _T("invalid wxDateTime"));
|
1999-11-30 16:55:00 -05:00
|
|
|
|
|
|
|
return m_time == datetime.m_time;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline bool wxDateTime::IsEarlierThan(const wxDateTime& datetime) const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-20 20:44:45 -05:00
|
|
|
wxASSERT_MSG( IsValid() && datetime.IsValid(), _T("invalid wxDateTime"));
|
1999-11-30 16:55:00 -05:00
|
|
|
|
|
|
|
return m_time < datetime.m_time;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline bool wxDateTime::IsLaterThan(const wxDateTime& datetime) const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-20 20:44:45 -05:00
|
|
|
wxASSERT_MSG( IsValid() && datetime.IsValid(), _T("invalid wxDateTime"));
|
1999-11-30 16:55:00 -05:00
|
|
|
|
|
|
|
return m_time > datetime.m_time;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline bool wxDateTime::IsStrictlyBetween(const wxDateTime& t1,
|
|
|
|
const wxDateTime& t2) const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
// no need for assert, will be checked by the functions we call
|
|
|
|
return IsLaterThan(t1) && IsEarlierThan(t2);
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline bool wxDateTime::IsBetween(const wxDateTime& t1,
|
|
|
|
const wxDateTime& t2) const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
// no need for assert, will be checked by the functions we call
|
|
|
|
return IsEqualTo(t1) || IsEqualTo(t2) || IsStrictlyBetween(t1, t2);
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline bool wxDateTime::IsSameDate(const wxDateTime& dt) const
|
1999-12-21 19:16:02 -05:00
|
|
|
{
|
2001-02-13 12:55:26 -05:00
|
|
|
Tm tm1 = GetTm(),
|
|
|
|
tm2 = dt.GetTm();
|
|
|
|
|
|
|
|
return tm1.year == tm2.year &&
|
|
|
|
tm1.mon == tm2.mon &&
|
|
|
|
tm1.mday == tm2.mday;
|
1999-12-21 19:16:02 -05:00
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline bool wxDateTime::IsSameTime(const wxDateTime& dt) const
|
1999-12-21 19:16:02 -05:00
|
|
|
{
|
|
|
|
// notice that we can't do something like this:
|
|
|
|
//
|
|
|
|
// m_time % MILLISECONDS_PER_DAY == dt.m_time % MILLISECONDS_PER_DAY
|
|
|
|
//
|
|
|
|
// because we have also to deal with (possibly) different DST settings!
|
|
|
|
Tm tm1 = GetTm(),
|
|
|
|
tm2 = dt.GetTm();
|
|
|
|
|
|
|
|
return tm1.hour == tm2.hour &&
|
|
|
|
tm1.min == tm2.min &&
|
|
|
|
tm1.sec == tm2.sec &&
|
|
|
|
tm1.msec == tm2.msec;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline bool wxDateTime::IsEqualUpTo(const wxDateTime& dt,
|
|
|
|
const wxTimeSpan& ts) const
|
1999-12-21 19:16:02 -05:00
|
|
|
{
|
2000-07-15 15:51:35 -04:00
|
|
|
return IsBetween(dt.Subtract(ts), dt.Add(ts));
|
1999-12-21 19:16:02 -05:00
|
|
|
}
|
|
|
|
|
1999-11-30 16:55:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDateTime arithmetics
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::Add(const wxTimeSpan& diff) const
|
1999-12-20 20:44:45 -05:00
|
|
|
{
|
|
|
|
wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
|
|
|
|
|
|
|
|
return wxDateTime(m_time + diff.GetValue());
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime& wxDateTime::Add(const wxTimeSpan& diff)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-20 20:44:45 -05:00
|
|
|
wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
|
1999-11-30 16:55:00 -05:00
|
|
|
|
|
|
|
m_time += diff.GetValue();
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime& wxDateTime::operator+=(const wxTimeSpan& diff)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
return Add(diff);
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::Subtract(const wxTimeSpan& diff) const
|
1999-12-20 20:44:45 -05:00
|
|
|
{
|
|
|
|
wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
|
|
|
|
|
|
|
|
return wxDateTime(m_time - diff.GetValue());
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime& wxDateTime::Subtract(const wxTimeSpan& diff)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-20 20:44:45 -05:00
|
|
|
wxASSERT_MSG( IsValid(), _T("invalid wxDateTime"));
|
1999-11-30 16:55:00 -05:00
|
|
|
|
|
|
|
m_time -= diff.GetValue();
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime& wxDateTime::operator-=(const wxTimeSpan& diff)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
2000-07-15 15:51:35 -04:00
|
|
|
return Subtract(diff);
|
1999-11-30 16:55:00 -05:00
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxTimeSpan wxDateTime::Subtract(const wxDateTime& datetime) const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-20 20:44:45 -05:00
|
|
|
wxASSERT_MSG( IsValid() && datetime.IsValid(), _T("invalid wxDateTime"));
|
1999-11-30 16:55:00 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
return wxTimeSpan(GetValue() - datetime.GetValue());
|
1999-11-30 16:55:00 -05:00
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::Add(const wxDateSpan& diff) const
|
1999-12-21 10:40:13 -05:00
|
|
|
{
|
|
|
|
return wxDateTime(*this).Add(diff);
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime& wxDateTime::Subtract(const wxDateSpan& diff)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
return Add(diff.Negate());
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::Subtract(const wxDateSpan& diff) const
|
1999-12-21 10:40:13 -05:00
|
|
|
{
|
2000-07-15 15:51:35 -04:00
|
|
|
return wxDateTime(*this).Subtract(diff);
|
1999-12-21 10:40:13 -05:00
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime& wxDateTime::operator-=(const wxDateSpan& diff)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
2000-07-15 15:51:35 -04:00
|
|
|
return Subtract(diff);
|
1999-11-30 16:55:00 -05:00
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime& wxDateTime::operator+=(const wxDateSpan& diff)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
return Add(diff);
|
|
|
|
}
|
|
|
|
|
1999-12-01 17:15:53 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDateTime and timezones
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateTime wxDateTime::ToTimezone(const wxDateTime::TimeZone& tz,
|
|
|
|
bool noDST) const
|
1999-12-01 17:15:53 -05:00
|
|
|
{
|
2000-01-02 18:17:55 -05:00
|
|
|
MODIFY_AND_RETURN( MakeTimezone(tz, noDST) );
|
1999-12-01 17:15:53 -05:00
|
|
|
}
|
|
|
|
|
1999-11-30 16:55:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-12-01 20:01:26 -05:00
|
|
|
// wxTimeSpan construction
|
1999-11-30 16:55:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxTimeSpan::wxTimeSpan(long hours,
|
|
|
|
long minutes,
|
|
|
|
long seconds,
|
|
|
|
long milliseconds)
|
1999-12-01 17:15:53 -05:00
|
|
|
{
|
|
|
|
// assign first to avoid precision loss
|
2000-01-06 10:42:32 -05:00
|
|
|
m_diff = hours;
|
1999-12-20 20:44:45 -05:00
|
|
|
m_diff *= 60l;
|
1999-12-01 17:15:53 -05:00
|
|
|
m_diff += minutes;
|
1999-12-20 20:44:45 -05:00
|
|
|
m_diff *= 60l;
|
1999-12-01 17:15:53 -05:00
|
|
|
m_diff += seconds;
|
1999-12-20 20:44:45 -05:00
|
|
|
m_diff *= 1000l;
|
1999-12-01 17:15:53 -05:00
|
|
|
m_diff += milliseconds;
|
|
|
|
}
|
|
|
|
|
1999-12-01 20:01:26 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxTimeSpan accessors
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxLongLong wxTimeSpan::GetSeconds() const
|
1999-12-01 20:01:26 -05:00
|
|
|
{
|
|
|
|
return m_diff / 1000l;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline int wxTimeSpan::GetMinutes() const
|
1999-12-01 20:01:26 -05:00
|
|
|
{
|
|
|
|
return (GetSeconds() / 60l).GetLo();
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline int wxTimeSpan::GetHours() const
|
1999-12-01 20:01:26 -05:00
|
|
|
{
|
|
|
|
return GetMinutes() / 60;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline int wxTimeSpan::GetDays() const
|
1999-12-01 20:01:26 -05:00
|
|
|
{
|
|
|
|
return GetHours() / 24;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline int wxTimeSpan::GetWeeks() const
|
1999-12-01 20:01:26 -05:00
|
|
|
{
|
|
|
|
return GetDays() / 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxTimeSpan arithmetics
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxTimeSpan wxTimeSpan::Add(const wxTimeSpan& diff) const
|
1999-12-20 20:44:45 -05:00
|
|
|
{
|
|
|
|
return wxTimeSpan(m_diff + diff.GetValue());
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxTimeSpan& wxTimeSpan::Add(const wxTimeSpan& diff)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
m_diff += diff.GetValue();
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxTimeSpan wxTimeSpan::Subtract(const wxTimeSpan& diff) const
|
1999-12-20 20:44:45 -05:00
|
|
|
{
|
|
|
|
return wxTimeSpan(m_diff - diff.GetValue());
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxTimeSpan& wxTimeSpan::Subtract(const wxTimeSpan& diff)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
m_diff -= diff.GetValue();
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxTimeSpan& wxTimeSpan::Multiply(int n)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-20 20:44:45 -05:00
|
|
|
m_diff *= (long)n;
|
1999-11-30 16:55:00 -05:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxTimeSpan wxTimeSpan::Multiply(int n) const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-20 20:44:45 -05:00
|
|
|
return wxTimeSpan(m_diff * (long)n);
|
1999-11-30 16:55:00 -05:00
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxTimeSpan wxTimeSpan::Abs() const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
return wxTimeSpan(GetValue().Abs());
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline bool wxTimeSpan::IsEqualTo(const wxTimeSpan& ts) const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
return GetValue() == ts.GetValue();
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline bool wxTimeSpan::IsLongerThan(const wxTimeSpan& ts) const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
return GetValue().Abs() > ts.GetValue().Abs();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDateSpan
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateSpan& wxDateSpan::operator+=(const wxDateSpan& other)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
m_years += other.m_years;
|
|
|
|
m_months += other.m_months;
|
|
|
|
m_weeks += other.m_weeks;
|
|
|
|
m_days += other.m_days;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateSpan& wxDateSpan::Add(const wxDateSpan& other)
|
|
|
|
{
|
|
|
|
return *this += other;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline wxDateSpan wxDateSpan::Add(const wxDateSpan& other) const
|
|
|
|
{
|
|
|
|
wxDateSpan ds(*this);
|
|
|
|
ds.Add(other);
|
|
|
|
return ds;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline wxDateSpan& wxDateSpan::Multiply(int factor)
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
1999-12-26 16:52:50 -05:00
|
|
|
m_years *= factor;
|
|
|
|
m_months *= factor;
|
|
|
|
m_weeks *= factor;
|
|
|
|
m_days *= factor;
|
1999-11-30 16:55:00 -05:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateSpan wxDateSpan::Multiply(int factor) const
|
1999-12-20 20:44:45 -05:00
|
|
|
{
|
2000-07-15 15:51:35 -04:00
|
|
|
wxDateSpan ds(*this);
|
|
|
|
ds.Multiply(factor);
|
|
|
|
return ds;
|
1999-12-20 20:44:45 -05:00
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateSpan wxDateSpan::Negate() const
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
return wxDateSpan(-m_years, -m_months, -m_weeks, -m_days);
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateSpan& wxDateSpan::Neg()
|
1999-11-30 16:55:00 -05:00
|
|
|
{
|
|
|
|
m_years = -m_years;
|
|
|
|
m_months = -m_months;
|
|
|
|
m_weeks = -m_weeks;
|
|
|
|
m_days = -m_days;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
inline wxDateSpan& wxDateSpan::operator-=(const wxDateSpan& other)
|
|
|
|
{
|
|
|
|
return *this += other.Negate();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline wxDateSpan& wxDateSpan::Subtract(const wxDateSpan& other)
|
|
|
|
{
|
|
|
|
return *this -= other;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline wxDateSpan wxDateSpan::Subtract(const wxDateSpan& other) const
|
|
|
|
{
|
|
|
|
wxDateSpan ds(*this);
|
|
|
|
ds.Subtract(other);
|
|
|
|
return ds;
|
|
|
|
}
|
|
|
|
|
1999-12-21 19:16:02 -05:00
|
|
|
#undef MILLISECONDS_PER_DAY
|
2000-01-02 18:17:55 -05:00
|
|
|
|
|
|
|
#undef MODIFY_AND_RETURN
|