The Battle for Wesnoth  1.15.3+dev
StructureTest.cpp
Go to the documentation of this file.
1 //
2 // M A R I A D B + +
3 //
4 // Copyright The ViaDuck Project 2016 - 2018.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 #include "StructureTest.h"
10 
11 TEST_F(StructureTest, testDateTime) {
12  date_time dt("2000-01-02 03:04:05.666");
13  date_time dt2(2000, 1, 2, 3, 4, 5, 666);
14 
15  EXPECT_EQ(dt, dt2);
16  EXPECT_FALSE(date_time::valid_date(2000, 0, 32));
17 
18  dt = dt.add_milliseconds(1000 * 60 * 60 * 24 * 10);
19  dt2 = dt2.add_days(10);
20 
21  EXPECT_EQ(dt, dt2);
22  EXPECT_EQ("2000-01-12 03:04:05", dt2.str(false));
23  EXPECT_EQ("2000-01-12 03:04:05.666", dt2.str(true));
24 }
25 
26 TEST_F(StructureTest, testTime) {
27  mariadb::time t("03:04:05.666");
28  mariadb::time t2(3, 4, 5, 666);
29 
30  EXPECT_EQ(t, t2);
31 
32  t = t.add_milliseconds(1000 * 60 * 60 * 5);
33  t2 = t2.add_hours(5);
34 
35  EXPECT_EQ(t, t2);
36  EXPECT_EQ("08:04:05", t2.str_time(false));
37  EXPECT_EQ("08:04:05.666", t2.str_time(true));
38 }
39 
40 TEST_F(StructureTest, testTimeSpan) {
41  date_time dt(2000, 1, 2, 3, 4, 5, 666);
42  date_time dt2(2000, 1, 5, 5, 5, 5, 999);
43 
44  time_span ts = dt2.time_between(dt);
45  EXPECT_EQ(3, ts.days());
46  EXPECT_EQ(2, ts.hours());
47  EXPECT_EQ(1, ts.minutes());
48  EXPECT_EQ(333, ts.milliseconds());
49 }
50 
51 TEST_F(StructureTest, testDecimal) {
52  decimal d("24.1234");
53 
54  EXPECT_EQ(24.1234, d.double64());
55  EXPECT_EQ("24.1234", d.str());
56 }
Class representing SQL time.
Definition: time.hpp:23
TEST_F(StructureTest, testDateTime)
f64 double64() const
Definition: decimal.hpp:29
#define d
time add_milliseconds(s32 milliseconds) const
Adds a certain amount of milliseconds to the current time.
Definition: time.cpp:181
u32 days() const
Get number of days.
Definition: time_span.cpp:82
u16 milliseconds() const
Get number of milliseconds.
Definition: time_span.cpp:110
const std::string str_time(bool with_millisecond=false) const
Converts the time to a string with the format hh:mm:ss[.nnn].
Definition: time.cpp:357
date_time add_milliseconds(s32 milliseconds) const
Add milliseconds to current date with second wrapping.
Definition: date_time.cpp:285
date_time add_days(s32 days) const
Add days to current date with month wrapping.
Definition: date_time.cpp:195
Class used to represent SQL date_time.
Definition: date_time.hpp:20
time_span time_between(const date_time &dt) const
Calculates the time_span between this date_time and dt.
Definition: date_time.cpp:348
time add_hours(s32 hours) const
Adds a certain amount of hours to the current time.
Definition: time.cpp:132
double t
Definition: astarsearch.cpp:64
u8 minutes() const
Get number of hours.
Definition: time_span.cpp:94
u8 hours() const
Get number of hours.
Definition: time_span.cpp:86
std::string str() const
Definition: decimal.hpp:21
const std::string str(bool with_millisecond=false) const
Converts the date and time to ISO 8601 string yyyy-mm-dd hh:mm:ss[.nnn].
Definition: date_time.cpp:565