From fb96cf856e152671099f464f5d1defa429bfc4ef Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 18 Jan 2007 14:06:37 +0000 Subject: [PATCH] added wxDateTime::GetDateOnly() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44242 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + docs/latex/wx/datetime.tex | 14 ++++++++++++++ include/wx/datetime.h | 6 ++++++ src/common/datetime.cpp | 10 ++++++++++ tests/datetime/datetimetest.cpp | 18 ++++++++++++++++++ 5 files changed, 49 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 1025cc9c4c..272b265ac6 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -94,6 +94,7 @@ Major new features in 2.8 release All: - Added wxSizerFlags::Shaped() and FixedMinSize() methods +- Added wxDateTime::GetDateOnly() wxMSW diff --git a/docs/latex/wx/datetime.tex b/docs/latex/wx/datetime.tex index 25b7cc0239..dd0a450766 100644 --- a/docs/latex/wx/datetime.tex +++ b/docs/latex/wx/datetime.tex @@ -862,6 +862,20 @@ Same as \helpref{Set}{wxdatetimesettm}. Returns {\tt true} if the object represents a valid time moment. +\membersection{wxDateTime::GetDateOnly}\label{wxdatetimegetdateonly} + +\constfunc{wxDateTime}{GetDateOnly}{\void} + +Returns the object having the same date component as this one but time of +00:00:00. + +\newsince{2.8.2} + +\wxheading{See also} + +\helpref{ResetTime}{wxdatetimeresettime} + + \membersection{wxDateTime::GetTm}\label{wxdatetimegettm} \constfunc{Tm}{GetTm}{\param{const TimeZone\& }{tz = Local}} diff --git a/include/wx/datetime.h b/include/wx/datetime.h index c65e1f64d8..2b88024a5a 100644 --- a/include/wx/datetime.h +++ b/include/wx/datetime.h @@ -639,6 +639,12 @@ public: // resets time to 00:00:00, doesn't change the date wxDateTime& ResetTime(); +#if wxABI_VERSION >= 20802 + // get the date part of this object only, i.e. the object which has the + // same date as this one but time of 00:00:00 + wxDateTime GetDateOnly() const; +#endif // wxABI 2.8.1+ + // the following functions don't change the values of the other // fields, i.e. SetMinute() won't change either hour or seconds value diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 315a4e1dc5..c40dedee2b 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -1496,6 +1496,16 @@ wxDateTime& wxDateTime::ResetTime() return *this; } +wxDateTime wxDateTime::GetDateOnly() const +{ + Tm tm = GetTm(); + tm.msec = + tm.sec = + tm.min = + tm.hour = 0; + return wxDateTime(tm); +} + // ---------------------------------------------------------------------------- // DOS Date and Time Format functions // ---------------------------------------------------------------------------- diff --git a/tests/datetime/datetimetest.cpp b/tests/datetime/datetimetest.cpp index feddc48085..db64b5c53e 100644 --- a/tests/datetime/datetimetest.cpp +++ b/tests/datetime/datetimetest.cpp @@ -191,6 +191,7 @@ private: CPPUNIT_TEST( TestDateParse ); CPPUNIT_TEST( TestTimeArithmetics ); CPPUNIT_TEST( TestDSTBug ); + CPPUNIT_TEST( TestDateOnly ); CPPUNIT_TEST_SUITE_END(); void TestLeapYears(); @@ -206,6 +207,7 @@ private: void TestDateParse(); void TestTimeArithmetics(); void TestDSTBug(); + void TestDateOnly(); DECLARE_NO_COPY_CLASS(DateTimeTestCase) }; @@ -920,4 +922,20 @@ void DateTimeTestCase::TestDSTBug() #endif // CHANGE_SYSTEM_DATE } +void DateTimeTestCase::TestDateOnly() +{ + wxDateTime dt(19, wxDateTime::Jan, 2007, 15, 01, 00); + + static const wxDateTime::wxDateTime_t DATE_ZERO = 0; + CPPUNIT_ASSERT_EQUAL( DATE_ZERO, dt.GetDateOnly().GetHour() ); + CPPUNIT_ASSERT_EQUAL( DATE_ZERO, dt.GetDateOnly().GetMinute() ); + CPPUNIT_ASSERT_EQUAL( DATE_ZERO, dt.GetDateOnly().GetSecond() ); + CPPUNIT_ASSERT_EQUAL( DATE_ZERO, dt.GetDateOnly().GetMillisecond() ); + + dt.ResetTime(); + CPPUNIT_ASSERT_EQUAL( wxDateTime(19, wxDateTime::Jan, 2007), dt ); + + CPPUNIT_ASSERT_EQUAL( wxDateTime::Today(), wxDateTime::Now().GetDateOnly() ); +} + #endif // wxUSE_DATETIME -- 2.45.2