2018-12-08 10:04:41 +00:00
|
|
|
#include <toml/datetime.hpp>
|
2017-04-21 03:56:39 +00:00
|
|
|
|
2022-09-16 11:16:01 +00:00
|
|
|
#include "unit_test.hpp"
|
|
|
|
|
2018-12-08 10:04:41 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_local_date)
|
2017-04-21 03:56:39 +00:00
|
|
|
{
|
2018-12-08 10:04:41 +00:00
|
|
|
const toml::local_date date(2018, toml::month_t::Jan, 1);
|
|
|
|
const toml::local_date date1(date);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(date == date1);
|
2017-04-21 03:56:39 +00:00
|
|
|
|
2018-12-08 10:04:41 +00:00
|
|
|
const std::chrono::system_clock::time_point tp(date);
|
|
|
|
const toml::local_date date2(tp);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(date == date2);
|
2017-04-21 06:55:04 +00:00
|
|
|
|
2018-12-08 10:04:41 +00:00
|
|
|
const toml::local_date date3(2017, toml::month_t::Dec, 31);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(date > date3);
|
2017-04-21 03:56:39 +00:00
|
|
|
|
2018-12-08 10:04:41 +00:00
|
|
|
std::ostringstream oss;
|
|
|
|
oss << date;
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(oss.str() == std::string("2018-01-01"));
|
2018-12-08 10:04:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_local_time)
|
|
|
|
{
|
|
|
|
const toml::local_time time(12, 30, 45);
|
|
|
|
const toml::local_time time1(time);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(time == time1);
|
2018-12-08 10:04:41 +00:00
|
|
|
|
2018-12-13 03:49:53 +00:00
|
|
|
const std::chrono::nanoseconds dur(time);
|
|
|
|
std::chrono::nanoseconds ns(0);
|
|
|
|
ns += std::chrono::hours (12);
|
|
|
|
ns += std::chrono::minutes(30);
|
|
|
|
ns += std::chrono::seconds(45);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(dur.count() == ns.count());
|
2018-12-08 10:04:41 +00:00
|
|
|
|
|
|
|
const toml::local_time time3(12, 15, 45);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(time > time3);
|
2018-12-08 10:04:41 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << time;
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(oss.str() == std::string("12:30:45"));
|
2018-12-08 10:04:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const toml::local_time time4(12, 30, 45, 123, 456);
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << time4;
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(oss.str() == std::string("12:30:45.123456"));
|
2018-12-08 10:04:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_time_offset)
|
|
|
|
{
|
|
|
|
const toml::time_offset time(9, 30);
|
|
|
|
const toml::time_offset time1(time);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(time == time1);
|
2018-12-08 10:04:41 +00:00
|
|
|
|
|
|
|
const std::chrono::minutes dur(time);
|
|
|
|
std::chrono::minutes m(0);
|
|
|
|
m += std::chrono::hours (9);
|
|
|
|
m += std::chrono::minutes(30);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(dur.count() == m.count());
|
2018-12-08 10:04:41 +00:00
|
|
|
|
|
|
|
const toml::time_offset time2(9, 0);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(time2 < time);
|
2018-12-08 10:04:41 +00:00
|
|
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << time;
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(oss.str() == std::string("+09:30"));
|
2018-12-08 10:04:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_local_datetime)
|
|
|
|
{
|
|
|
|
const toml::local_datetime dt(toml::local_date(2018, toml::month_t::Jan, 1),
|
|
|
|
toml::local_time(12, 30, 45));
|
|
|
|
const toml::local_datetime dt1(dt);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(dt == dt1);
|
2018-12-08 10:04:41 +00:00
|
|
|
|
|
|
|
const std::chrono::system_clock::time_point tp(dt);
|
|
|
|
const toml::local_datetime dt2(tp);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(dt == dt2);
|
2018-12-08 10:04:41 +00:00
|
|
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << dt;
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(oss.str() == std::string("2018-01-01T12:30:45"));
|
2018-12-08 10:04:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_offset_datetime)
|
|
|
|
{
|
|
|
|
const toml::offset_datetime dt(toml::local_date(2018, toml::month_t::Jan, 1),
|
|
|
|
toml::local_time(12, 30, 45),
|
|
|
|
toml::time_offset(9, 30));
|
|
|
|
const toml::offset_datetime dt1(dt);
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(dt == dt1);
|
2018-12-08 10:04:41 +00:00
|
|
|
|
|
|
|
const std::chrono::system_clock::time_point tp1(dt);
|
|
|
|
const toml::offset_datetime dt2(tp1);
|
|
|
|
const std::chrono::system_clock::time_point tp2(dt2);
|
2019-06-21 05:43:13 +00:00
|
|
|
const bool tp_same = (tp1 == tp2);
|
|
|
|
BOOST_TEST(tp_same);
|
2017-04-21 06:55:04 +00:00
|
|
|
|
2018-12-08 10:04:41 +00:00
|
|
|
{
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << dt;
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(oss.str() == std::string("2018-01-01T12:30:45+09:30"));
|
2018-12-08 10:04:41 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
const toml::offset_datetime dt3(
|
|
|
|
toml::local_date(2018, toml::month_t::Jan, 1),
|
|
|
|
toml::local_time(12, 30, 45),
|
|
|
|
toml::time_offset(0, 0));
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << dt3;
|
2019-06-21 05:43:13 +00:00
|
|
|
BOOST_TEST(oss.str() == std::string("2018-01-01T12:30:45Z"));
|
2018-12-08 10:04:41 +00:00
|
|
|
}
|
2017-04-21 03:56:39 +00:00
|
|
|
}
|