X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2f02cb8966964ea7a6f5d875ed9f3434ea05ab59..6e807169c4b63b29b42c36ae15141a31adb29204:/include/wx/datetime.inl diff --git a/include/wx/datetime.inl b/include/wx/datetime.inl index 1ae112d5ad..5b1d4652e3 100644 --- a/include/wx/datetime.inl +++ b/include/wx/datetime.inl @@ -35,7 +35,7 @@ wxDateTime::Country wxDateTime::GetCountry() const unsigned int wxDateTime::TIME_T_FACTOR = 1000; #endif // wxDEFINE_TIME_CONSTANTS -wxDateTime::IsInStdRange() const +bool wxDateTime::IsInStdRange() const { return m_time >= 0l && (m_time / (long)TIME_T_FACTOR) < LONG_MAX; } @@ -75,6 +75,11 @@ wxDateTime::wxDateTime(const Tm& tm) Set(tm); } +wxDateTime::wxDateTime(double jdn) +{ + Set(jdn); +} + wxDateTime& wxDateTime::Set(const Tm& tm) { wxASSERT_MSG( tm.IsValid(), _T("invalid broken down date/time") ); @@ -238,7 +243,61 @@ wxDateTime& wxDateTime::operator+=(const wxDateSpan& diff) } // ---------------------------------------------------------------------------- -// wxTimeSpan +// wxDateTime and timezones +// ---------------------------------------------------------------------------- + +wxDateTime wxDateTime::ToTimezone(const wxDateTime::TimeZone& tz) const +{ + return wxDateTime(*this).MakeTimezone(tz); +} + +// ---------------------------------------------------------------------------- +// wxTimeSpan construction +// ---------------------------------------------------------------------------- + +wxTimeSpan::wxTimeSpan(int hours, int minutes, int seconds, int milliseconds) +{ + // assign first to avoid precision loss + m_diff = hours; + m_diff *= 60; + m_diff += minutes; + m_diff *= 60; + m_diff += seconds; + m_diff *= 1000; + m_diff += milliseconds; +} + +// ---------------------------------------------------------------------------- +// wxTimeSpan accessors +// ---------------------------------------------------------------------------- + +wxLongLong wxTimeSpan::GetSeconds() const +{ + return m_diff / 1000l; +} + +int wxTimeSpan::GetMinutes() const +{ + return (GetSeconds() / 60l).GetLo(); +} + +int wxTimeSpan::GetHours() const +{ + return GetMinutes() / 60; +} + +int wxTimeSpan::GetDays() const +{ + return GetHours() / 24; +} + +int wxTimeSpan::GetWeeks() const +{ + return GetDays() / 7; +} + +// ---------------------------------------------------------------------------- +// wxTimeSpan arithmetics // ---------------------------------------------------------------------------- wxTimeSpan& wxTimeSpan::Add(const wxTimeSpan& diff) @@ -325,4 +384,3 @@ wxDateSpan& wxDateSpan::Neg() return *this; } -