Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Date.ut.cpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#include "Date.hpp"
18
19#include <boost/test/unit_test.hpp>
20
21namespace std::chrono {
22template <typename RepT, typename PeriodT>
23ostream& operator<<(ostream& os, duration<RepT, PeriodT> d)
24{
25 return os << d.count();
26}
27} // namespace std::chrono
28
29using namespace std;
30using namespace toolbox;
31
33
38
40{
41 BOOST_CHECK_EQUAL(2456731_jd, ymd_to_jd(2014, 3, 14));
42 // AD 1978 January 1, 0h UT is JD 2443509.5 and AD 1978 July 21, 15h UT, is JD 2443711.125.
43 BOOST_CHECK_EQUAL(2443510_jd, ymd_to_jd(1978, 1, 1));
44 BOOST_CHECK_EQUAL(2443711_jd, ymd_to_jd(1978, 7, 21));
45}
46
51
56
61
63{
65 BOOST_CHECK(!parse_time("20180824x05:32:29.123"sv));
66 BOOST_CHECK(!parse_time("20180824-05x32:29.123"sv));
67
68 BOOST_CHECK_EQUAL(ms_since_epoch(*parse_time("00000000-00:00:00.000"sv)), 0);
69 BOOST_CHECK_EQUAL(ms_since_epoch(*parse_time("20180824"sv)), 1535068800000);
70 BOOST_CHECK_EQUAL(ms_since_epoch(*parse_time("20180824-05:32:29"sv)), 1535088749000);
71 BOOST_CHECK_EQUAL(ms_since_epoch(*parse_time("20180824-05:32:29.123"sv)), 1535088749123);
72 BOOST_CHECK_EQUAL(us_since_epoch(*parse_time("20180824-05:32:29.123456"sv)), 1535088749123456);
73
74 BOOST_CHECK_EQUAL(ms_since_epoch(*parse_time("00000000T00:00:00.000"sv)), 0);
75 BOOST_CHECK_EQUAL(ms_since_epoch(*parse_time("20180824"sv)), 1535068800000);
76 BOOST_CHECK_EQUAL(ms_since_epoch(*parse_time("20180824T05:32:29"sv)), 1535088749000);
77 BOOST_CHECK_EQUAL(ms_since_epoch(*parse_time("20180824T05:32:29.123"sv)), 1535088749123);
78 BOOST_CHECK_EQUAL(us_since_epoch(*parse_time("20180824T05:32:29.123456"sv)), 1535088749123456);
79}
80
BOOST_AUTO_TEST_CASE(YmdToIsoCase)
Definition Date.ut.cpp:34
BOOST_CHECK_EQUAL(v.size(), 10U)
ostream & operator<<(ostream &os, duration< RepT, PeriodT > d)
Definition Timer.ut.cpp:23
STL namespace.
constexpr WallTime jd_to_time(JDay jd) noexcept
Julian day to Unix time.
Definition Date.hpp:124
constexpr std::int64_t us_since_epoch(std::chrono::time_point< ClockT, Duration > t) noexcept
Definition Time.hpp:183
constexpr std::int64_t ms_since_epoch(std::chrono::time_point< ClockT, Duration > t) noexcept
Definition Time.hpp:176
constexpr DurationT time_since_epoch(std::chrono::time_point< ClockT, Duration > t) noexcept
Definition Time.hpp:168
constexpr auto jd_to_iso(JDay jd) noexcept
Julian day to ISO8601.
Definition Date.hpp:79
constexpr auto ymd_to_iso(int year, int mon, int mday) noexcept
Gregorian to ISO8601 date.
Definition Date.hpp:46
constexpr std::optional< WallTime > parse_time(std::string_view sv) noexcept
Definition Date.hpp:181
constexpr auto ymd_to_jd(int year, int mon, int mday) noexcept
Gregorian date to Julian day.
Definition Date.hpp:54
constexpr auto parse_date(std::string_view sv) noexcept
Definition Date.hpp:163
std::string_view sv
Definition Tokeniser.hpp:26
constexpr auto bind() noexcept
Definition Slot.hpp:92
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))