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 //
10 #include <anna/time/Date.hpp>
11 #include <anna/time/functions.hpp>
13 #include <gtest/gtest.h>
19 TEST(date, Conversions)
21 anna::time::functions::initialize();
22 anna::time::Date current, current2;
24 unsigned int ntptime = current.getNtpTimestamp();
25 time_t unixtime = current.getUnixTimestamp();
26 current2.storeNtp(ntptime);
27 std::string ntpStr = current2.asString();
28 current2.storeUnix(unixtime);
29 std::string unixStr = current2.asString();
30 EXPECT_EQ(ntpStr, unixStr);
32 anna::time::Date myBirth("CET"); // 19 December 1974, 10:00 (GMT+1 = UTC + 1 = CET)
33 myBirth.store("19741219101500"); // yyyymmddHHmmss
34 anna::time::Date same_moment_canary_island("GMT");
35 same_moment_canary_island.store(myBirth.getUnixTimestamp());
37 EXPECT_EQ(same_moment_canary_island.yyyymmddHHmmss(), myBirth.yyyymmddHHmmss());
39 anna::time::Date birthday("EET");
40 birthday.store(same_moment_canary_island.getTm(), "GMT"); // TZ origin = "GMT"
41 EXPECT_EQ(birthday.getUnixTimestamp(), myBirth.getUnixTimestamp());
45 EXPECT_EQ(myBirth.asString(), birthday.asString());
46 EXPECT_EQ(myBirth.yyyymmddHHmmss(), birthday.yyyymmddHHmmss());
49 EXPECT_EQ(myBirth.yyyymmddHHmmss(), "19741219091500");
51 // Adding 18 years to 'myBirth':
52 same_moment_canary_island.setTz("CET");
53 anna::time::Date eighteen("CET");
54 struct tm Tm = myBirth.getTm();
56 eighteen.store(Tm, "GMT");
57 EXPECT_TRUE(eighteen >= same_moment_canary_island);
58 EXPECT_EQ(eighteen.yyyymmddHHmmss(), "19921219101500");
63 int main(int argc, char **argv)
65 testing::InitGoogleTest(&argc, argv);
66 return RUN_ALL_TESTS();