forked from fnc12/sqlite_orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatetime_function_tests.cpp
More file actions
65 lines (58 loc) · 1.89 KB
/
datetime_function_tests.cpp
File metadata and controls
65 lines (58 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <sqlite_orm/sqlite_orm.h>
#include <catch2/catch.hpp>
using namespace sqlite_orm;
TEST_CASE("time") {
auto storage = make_storage({});
{
auto rows = storage.select(time("12:00", "localtime"));
REQUIRE(rows.size() == 1);
REQUIRE(!rows.front().empty());
}
{
auto rows = storage.select(time("12:00", "utc"));
REQUIRE(rows.size() == 1);
REQUIRE(!rows.front().empty());
}
}
TEST_CASE("julianday") {
struct Test {
std::string text;
};
auto storage = make_storage({}, make_table("test", make_column("text", &Test::text)));
storage.sync_schema();
auto singleTestCase = [&storage](const std::string &arg, double expected) {
{
auto rows = storage.select(julianday(arg));
REQUIRE(rows.size() == 1);
REQUIRE((rows.front() - expected) < 0.001); // too much precision
}
{
storage.insert(Test{arg});
auto rows = storage.select(julianday(&Test::text));
REQUIRE(rows.size() == 1);
REQUIRE((rows.front() - expected) < 0.001);
storage.remove_all<Test>();
}
};
singleTestCase("2016-10-18", 2457679.5);
singleTestCase("2016-10-18 16:45", 2457680.19791667);
singleTestCase("2016-10-18 16:45:30", 2457680.19826389);
}
TEST_CASE("datetime") {
auto storage = make_storage({});
auto rows = storage.select(datetime("now"));
REQUIRE(rows.size() == 1);
REQUIRE(!rows.front().empty());
}
TEST_CASE("date") {
auto storage = make_storage({});
auto rows = storage.select(date("now", "start of month", "+1 month", "-1 day"));
REQUIRE(rows.size() == 1);
REQUIRE(!rows.front().empty());
}
TEST_CASE("strftime") {
auto storage = make_storage({});
auto rows = storage.select(strftime("%Y %m %d", "now"));
REQUIRE(rows.size() == 1);
REQUIRE(!rows.front().empty());
}