X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=test%2Ftime%2Fmain.cpp;h=b8ddcc03463926e84224ae9ffdd1e4e8e9990f2c;hb=b8c96c2917b9d29976a8771659d70bfb0881c133;hp=38201995efa43981c8913e684c2a187ffadc4adc;hpb=10acee039e75b859b11fd809ce22fb2aecce47e2;p=anna.git diff --git a/test/time/main.cpp b/test/time/main.cpp index 3820199..b8ddcc0 100644 --- a/test/time/main.cpp +++ b/test/time/main.cpp @@ -51,10 +51,9 @@ using namespace anna; // http://www.boost.org/doc/libs/1_44_0/libs/test/doc/html/utf/testing-tools/reference.html BOOST_AUTO_TEST_CASE(date) { - const char * tzarg = NULL; anna::time::functions::initialize(); anna::time::Date current, current2; - current.setCurrent(); + current.setNow(); unsigned int ntptime = current.getNtpTimestamp(); time_t unixtime = current.getUnixTimestamp(); current2.storeNtp(ntptime); @@ -62,26 +61,33 @@ BOOST_AUTO_TEST_CASE(date) { current2.storeUnix(unixtime); std::string unixStr = current2.asString(); BOOST_REQUIRE_EQUAL(ntpStr, unixStr); + anna::time::Date myBirth("CET"); // 19 December 1974, 10:00 (GMT+1 = UTC + 1 = CET) - //anna::time::Date myBirth; // if Context TZ = shell TZ = "CET" myBirth.store("19741219101500"); // yyyymmddHHmmss anna::time::Date same_moment_canary_island("GMT"); same_moment_canary_island.store(myBirth.getUnixTimestamp()); - myBirth.setTzContext("GMT"); + myBirth.setTz("GMT"); BOOST_REQUIRE_EQUAL(same_moment_canary_island.yyyymmddHHmmss(), myBirth.yyyymmddHHmmss()); + anna::time::Date birthday("EET"); birthday.store(same_moment_canary_island.getTm(), "GMT"); // TZ origin = "GMT" - //BOOST_REQUIRE_EQUAL(birthday, myBirth); BOOST_REQUIRE_EQUAL(birthday.getUnixTimestamp(), myBirth.getUnixTimestamp()); - myBirth.setTzContext(anna::time::functions::getLocalTz().getValue().c_str()); - birthday.setTzContext(anna::time::functions::getLocalTz().getValue().c_str()); // Go from "EET" to "CET" - // TODO: review the following test case: - //BOOST_REQUIRE_EQUAL(myBirth.yyyymmddHHmmss(), birthday.yyyymmddHHmmss()); + + myBirth.setTz(); + birthday.setTz(); + BOOST_REQUIRE_EQUAL(myBirth.asString(), birthday.asString()); + BOOST_REQUIRE_EQUAL(myBirth.yyyymmddHHmmss(), birthday.yyyymmddHHmmss()); + + myBirth.setTz("GMT"); + BOOST_REQUIRE_EQUAL(myBirth.yyyymmddHHmmss(), "19741219091500"); + // Adding 18 years to 'myBirth': + same_moment_canary_island.setTz("CET"); + anna::time::Date eighteen("CET"); struct tm Tm = myBirth.getTm(); Tm.tm_year += 18; - anna::time::Date eighteen("CET"); - eighteen.store(Tm); + eighteen.store(Tm, "GMT"); BOOST_REQUIRE(eighteen >= same_moment_canary_island); + BOOST_REQUIRE_EQUAL(eighteen.yyyymmddHHmmss(), "19921219101500"); }