]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxDateTime::GetDateOnly()
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 18 Jan 2007 14:06:37 +0000 (14:06 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 18 Jan 2007 14:06:37 +0000 (14:06 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44242 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/datetime.tex
include/wx/datetime.h
src/common/datetime.cpp
tests/datetime/datetimetest.cpp

index 1025cc9c4c2f39c245cb9b233a0028faa19d6005..272b265ac6a76edcca6d930ac772c27e99790fef 100644 (file)
@@ -94,6 +94,7 @@ Major new features in 2.8 release
 All:
 
 - Added wxSizerFlags::Shaped() and FixedMinSize() methods
+- Added wxDateTime::GetDateOnly()
 
 wxMSW
 
index 25b7cc0239fa7021909185d9d4944e2c7bb1d9b2..dd0a45076612d6c04ace4da1f7123d56c624e071 100644 (file)
@@ -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}}
index c65e1f64d80f0cff877581bb1c68a6c5498c8b8d..2b88024a5ae26d7ddc25606f6e5ca3fbf719518e 100644 (file)
@@ -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
 
index 315a4e1dc525b437714b3853f0b7a0ca92a30e3a..c40dedee2b2842d14dac35edec5add9f1af31f26 100644 (file)
@@ -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
 // ----------------------------------------------------------------------------
index feddc48085d2d95cb4a10d3b0498eeecd33bcba7..db64b5c53ecb8dbf900b40a7405d776bd0837aeb 100644 (file)
@@ -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