From dad9e26fc5f80aaba3b18dd47a6392cdef7f1ef0 Mon Sep 17 00:00:00 2001 From: Gerd von Egidy Date: Fri, 10 Feb 2012 13:28:03 +0100 Subject: [PATCH] one more time_t fix, the other functions look good --- src/timefunc.cpp | 5 +++-- src/timefunc.hxx | 2 +- test/test_timefunc.cpp | 13 +++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/timefunc.cpp b/src/timefunc.cpp index 1288301..e956ee3 100644 --- a/src/timefunc.cpp +++ b/src/timefunc.cpp @@ -69,9 +69,10 @@ double prec_time(void) } // converts ISO-DATE: 2003-06-13 -int date_to_seconds(const std::string &date) +time_t date_to_seconds(const std::string &date) { - int rtn = -1, year = -1, month = -1, day = -1; + time_t rtn = 0; + int year = -1, month = -1, day = -1; string::size_type pos = date.find("-"); if (pos == string::npos) diff --git a/src/timefunc.hxx b/src/timefunc.hxx index 8db994c..96530b4 100644 --- a/src/timefunc.hxx +++ b/src/timefunc.hxx @@ -33,7 +33,7 @@ on this file might be covered by the GNU General Public License. double prec_time(void); -int date_to_seconds(const std::string &date); +time_t date_to_seconds(const std::string &date); std::string make_nice_time(int seconds); std::string format_full_time(time_t seconds); diff --git a/test/test_timefunc.cpp b/test/test_timefunc.cpp index f4bc4f2..58dcaf5 100644 --- a/test/test_timefunc.cpp +++ b/test/test_timefunc.cpp @@ -449,4 +449,17 @@ BOOST_AUTO_TEST_CASE(FormatFullTime) BOOST_CHECK_EQUAL("17.10.2011 11:33", format_full_time(seconds)); } +BOOST_AUTO_TEST_CASE(DateToSeconds1) +{ + // no DST + BOOST_CHECK_EQUAL(1325372400, date_to_seconds("2012-01-01")); +} + +BOOST_AUTO_TEST_CASE(DateToSeconds2) +{ + // DST + BOOST_CHECK_EQUAL(1341093600, date_to_seconds("2012-07-01")); +} + + BOOST_AUTO_TEST_SUITE_END() -- 1.7.1