1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #define BOOST_TEST_MODULE ANNA_TIME_TEST
11 #include <anna/test/clang_specific.hpp>
12 #include <boost/test/included/unit_test.hpp>
17 #include <anna/time/Date.hpp>
18 #include <anna/time/functions.hpp>
23 // see http://www.boost.org/doc/libs/1_44_0/libs/test/doc/html/utf/testing-tools.html
24 // http://www.boost.org/doc/libs/1_44_0/libs/test/doc/html/utf/testing-tools/reference.html
26 BOOST_AUTO_TEST_CASE(date) {
27 anna::time::functions::initialize();
28 anna::time::Date current, current2;
30 unsigned int ntptime = current.getNtpTimestamp();
31 time_t unixtime = current.getUnixTimestamp();
32 current2.storeNtp(ntptime);
33 std::string ntpStr = current2.asString();
34 current2.storeUnix(unixtime);
35 std::string unixStr = current2.asString();
36 BOOST_REQUIRE_EQUAL(ntpStr, unixStr);
38 anna::time::Date myBirth("CET"); // 19 December 1974, 10:00 (GMT+1 = UTC + 1 = CET)
39 myBirth.store("19741219101500"); // yyyymmddHHmmss
40 anna::time::Date same_moment_canary_island("GMT");
41 same_moment_canary_island.store(myBirth.getUnixTimestamp());
43 BOOST_REQUIRE_EQUAL(same_moment_canary_island.yyyymmddHHmmss(), myBirth.yyyymmddHHmmss());
45 anna::time::Date birthday("EET");
46 birthday.store(same_moment_canary_island.getTm(), "GMT"); // TZ origin = "GMT"
47 BOOST_REQUIRE_EQUAL(birthday.getUnixTimestamp(), myBirth.getUnixTimestamp());
51 BOOST_REQUIRE_EQUAL(myBirth.asString(), birthday.asString());
52 BOOST_REQUIRE_EQUAL(myBirth.yyyymmddHHmmss(), birthday.yyyymmddHHmmss());
55 BOOST_REQUIRE_EQUAL(myBirth.yyyymmddHHmmss(), "19741219091500");
57 // Adding 18 years to 'myBirth':
58 same_moment_canary_island.setTz("CET");
59 anna::time::Date eighteen("CET");
60 struct tm Tm = myBirth.getTm();
62 eighteen.store(Tm, "GMT");
63 BOOST_REQUIRE(eighteen >= same_moment_canary_island);
64 BOOST_REQUIRE_EQUAL(eighteen.yyyymmddHHmmss(), "19921219101500");