Skip to content

Commit

Permalink
Test for timestamp parsing and formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
joto committed Oct 28, 2011
1 parent 81b0ec8 commit a6bf9cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/osmium/utils/timestamp.hpp
Expand Up @@ -63,7 +63,7 @@ namespace Osmium {
the year will have 5 digits). And by setting the size
afterwards from the result of strftime we make sure thats set
right, too. */
s.resize(strftime(const_cast<char *>(s.c_str()), timestamp_length, timestamp_format(), tm));
s.resize(strftime(const_cast<char*>(s.c_str()), timestamp_length, timestamp_format(), tm));
return s;
}

Expand Down
26 changes: 26 additions & 0 deletions test/testgroup_plain/utils/test_timestamp.cpp
@@ -0,0 +1,26 @@
#define BOOST_TEST_DYN_LINK
#ifdef STAND_ALONE
# define BOOST_TEST_MODULE Main
#endif
#include <boost/test/unit_test.hpp>

#include <osmium/utils/timestamp.hpp>

BOOST_AUTO_TEST_SUITE(Timestamp)

BOOST_AUTO_TEST_CASE(zero) {
BOOST_CHECK_EQUAL(std::string(""), Osmium::Utils::Timestamp::to_iso(0));
}

BOOST_AUTO_TEST_CASE(second_after_epoch) {
BOOST_CHECK_EQUAL(std::string("1970-01-01T00:00:01Z"), Osmium::Utils::Timestamp::to_iso(1));
}

BOOST_AUTO_TEST_CASE(sometime) {
const char* ts= "2011-10-28T09:12:00Z";
time_t t = Osmium::Utils::Timestamp::parse_iso(ts);
BOOST_CHECK_EQUAL(std::string(ts), Osmium::Utils::Timestamp::to_iso(t));
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit a6bf9cb

Please sign in to comment.