You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2009/07/02 00:14:08 UTC
svn commit: r790406 - in /activemq/activemq-cpp/trunk/activemq-cpp/src:
main/decaf/util/Date.cpp main/decaf/util/Date.h
test/decaf/util/DateTest.cpp test/decaf/util/DateTest.h
Author: tabish
Date: Wed Jul 1 22:14:08 2009
New Revision: 790406
URL: http://svn.apache.org/viewvc?rev=790406&view=rev
Log:
Working on: http://issues.apache.org/activemq/browse/AMQCPP-250
Implement the Date class toString method to produce a Java equivalent Date/Time string. Add additional Date class tests to the unit tests.
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.h
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/DateTest.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/DateTest.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.cpp?rev=790406&r1=790405&r2=790406&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.cpp Wed Jul 1 22:14:08 2009
@@ -97,3 +97,26 @@
bool Date::operator<( const Date& value ) const {
return ( this->time < value.time );
}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Date::toString() const {
+
+ apr_time_exp_t exploded;
+ char buffer[80] = {0};
+ apr_size_t resultSize = 0;
+
+ // dow mon dd hh:mm:ss zzz yyyy
+ static char format[] = "%a %b %d %T %Z %Y";
+
+ // Explode time to local time.
+ if( apr_time_exp_lt( &exploded, this->time ) != APR_SUCCESS ) {
+ return "";
+ }
+
+ // Now format the exploded time into our desired format.
+ if( apr_strftime( &buffer[0], &resultSize, sizeof(buffer) / sizeof(char), format, &exploded ) != APR_SUCCESS ) {
+ return "";
+ }
+
+ return &buffer[0];
+}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.h?rev=790406&r1=790405&r2=790406&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.h Wed Jul 1 22:14:08 2009
@@ -20,6 +20,7 @@
#include <decaf/util/Config.h>
#include <decaf/lang/Comparable.h>
+#include <string>
namespace decaf{
namespace util{
@@ -99,6 +100,29 @@
*/
bool before( const Date& when ) const;
+ /**
+ * Converts this Date object to a String of the form:
+ *
+ * dow mon dd hh:mm:ss zzz yyyy
+ *
+ * where:
+ *
+ * - dow is the day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
+ * - mon is the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
+ * - dd is the day of the month (01 through 31), as two decimal digits.
+ * - hh is the hour of the day (00 through 23), as two decimal digits.
+ * - mm is the minute within the hour (00 through 59), as two decimal digits.
+ * - ss is the second within the minute (00 through 61, as two decimal digits.
+ * - zzz is the time zone (and may reflect daylight saving time). Standard time
+ * zone abbreviations include those recognized by the method parse. If time
+ * zone information is not available, then zzz is empty - that is, it consists
+ * of no characters at all.
+ * - yyyy is the year, as four decimal digits.
+ *
+ * @return the String representation of the Date object.
+ */
+ std::string toString() const;
+
public: // Comparable
/**
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/DateTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/DateTest.cpp?rev=790406&r1=790405&r2=790406&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/DateTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/DateTest.cpp Wed Jul 1 22:14:08 2009
@@ -25,7 +25,8 @@
using namespace decaf::util;
using namespace decaf::lang;
-void DateTest::test(){
+////////////////////////////////////////////////////////////////////////////////
+void DateTest::test() {
Date date1;
CPPUNIT_ASSERT( date1.getTime() != 0 );
@@ -38,5 +39,27 @@
CPPUNIT_ASSERT( date1.after(date2) == false );
Date date3 = date1;
+
+ // Test Comparable interface
CPPUNIT_ASSERT( date1.equals( date3 ) == true );
+ CPPUNIT_ASSERT( date3.equals( date1 ) == true );
+ CPPUNIT_ASSERT( date1.equals( date2 ) == false );
+ CPPUNIT_ASSERT( date1.compareTo( date2 ) < 0 );
+ CPPUNIT_ASSERT( date2.compareTo( date1 ) > 0 );
+ CPPUNIT_ASSERT( date1.compareTo( date3 ) == 0 );
+ CPPUNIT_ASSERT( date3.compareTo( date1 ) == 0 );
+ CPPUNIT_ASSERT( date1 < date2 );
+ CPPUNIT_ASSERT( !( date2 < date1 ) );
+ CPPUNIT_ASSERT( !( date1 < date3 ) );
+ CPPUNIT_ASSERT( date3 == date1 );
+ CPPUNIT_ASSERT( date1 == date3 );
+ CPPUNIT_ASSERT( !( date1 == date2 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DateTest::testToString() {
+
+ Date now;
+ CPPUNIT_ASSERT( now.toString() != "" );
+ CPPUNIT_ASSERT( now.toString().size() >= 20 );
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/DateTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/DateTest.h?rev=790406&r1=790405&r2=790406&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/DateTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/DateTest.h Wed Jul 1 22:14:08 2009
@@ -24,17 +24,20 @@
namespace decaf{
namespace util{
- class DateTest : public CppUnit::TestFixture
- {
+ class DateTest : public CppUnit::TestFixture {
+
CPPUNIT_TEST_SUITE( DateTest );
CPPUNIT_TEST( test );
+ CPPUNIT_TEST( testToString );
CPPUNIT_TEST_SUITE_END();
public:
+
DateTest(){};
virtual ~DateTest(){};
void test();
+ void testToString();
};