2020-03-12 15:23:25 +00:00
|
|
|
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
|
2021-01-02 15:48:47 +00:00
|
|
|
//# Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
|
2020-03-12 15:23:25 +00:00
|
|
|
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
2020-04-10 16:46:00 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-03-12 15:23:25 +00:00
|
|
|
|
2020-01-11 21:15:24 +00:00
|
|
|
#pragma once
|
2021-10-23 09:22:41 +00:00
|
|
|
#include "common.h"
|
2021-10-24 10:21:32 +00:00
|
|
|
#include "header_start.h"
|
2020-01-11 21:15:24 +00:00
|
|
|
|
2020-07-25 17:37:30 +00:00
|
|
|
TOML_NAMESPACE_START
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief A local date.
|
2020-04-10 16:46:00 +00:00
|
|
|
struct TOML_TRIVIAL_ABI date
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief The year component.
|
2020-01-11 21:15:24 +00:00
|
|
|
uint16_t year;
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief The month component, from 1 - 12.
|
2020-01-11 21:15:24 +00:00
|
|
|
uint8_t month;
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief The day component, from 1 - 31.
|
2020-01-11 21:15:24 +00:00
|
|
|
uint8_t day;
|
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
/// \brief Equality operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator==(date lhs, date rhs) noexcept
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
2021-10-23 09:22:41 +00:00
|
|
|
return lhs.year == rhs.year && lhs.month == rhs.month && lhs.day == rhs.day;
|
2020-01-11 21:15:24 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
/// \brief Inequality operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator!=(date lhs, date rhs) noexcept
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
2021-10-23 09:22:41 +00:00
|
|
|
return lhs.year != rhs.year || lhs.month != rhs.month || lhs.day != rhs.day;
|
2020-01-11 21:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 09:22:41 +00:00
|
|
|
private:
|
|
|
|
TOML_NODISCARD
|
|
|
|
TOML_ALWAYS_INLINE
|
|
|
|
static constexpr uint32_t pack(const date& d) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
2021-10-23 09:22:41 +00:00
|
|
|
return (static_cast<uint32_t>(d.year) << 16) | (static_cast<uint32_t>(d.month) << 8)
|
|
|
|
| static_cast<uint32_t>(d.day);
|
2020-03-01 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 09:22:41 +00:00
|
|
|
public:
|
2020-03-01 14:56:40 +00:00
|
|
|
/// \brief Less-than operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator<(date lhs, date rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return pack(lhs) < pack(rhs);
|
|
|
|
}
|
2020-02-03 09:12:43 +00:00
|
|
|
|
2020-03-01 14:56:40 +00:00
|
|
|
/// \brief Less-than-or-equal-to operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator<=(date lhs, date rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return pack(lhs) <= pack(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Greater-than operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator>(date lhs, date rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return pack(lhs) > pack(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Greater-than-or-equal-to operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator>=(date lhs, date rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return pack(lhs) >= pack(rhs);
|
|
|
|
}
|
2020-01-11 21:15:24 +00:00
|
|
|
};
|
|
|
|
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \brief Prints a date out to a stream as `YYYY-MM-DD` (per RFC 3339).
|
|
|
|
/// \detail \cpp
|
2020-08-11 13:34:03 +00:00
|
|
|
/// std::cout << toml::date{ 1987, 3, 16 } << "\n";
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \ecpp
|
2021-10-23 09:22:41 +00:00
|
|
|
///
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \out
|
|
|
|
/// 1987-03-16
|
|
|
|
/// \eout
|
2020-04-02 21:39:21 +00:00
|
|
|
template <typename Char>
|
2021-10-23 09:22:41 +00:00
|
|
|
inline std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>& lhs, const date& rhs)
|
2020-03-03 08:10:07 +00:00
|
|
|
{
|
|
|
|
impl::print_to_stream(rhs, lhs);
|
|
|
|
return lhs;
|
|
|
|
}
|
|
|
|
|
2021-10-23 09:22:41 +00:00
|
|
|
#if !defined(DOXYGEN) && !TOML_HEADER_ONLY
|
|
|
|
extern template TOML_API
|
|
|
|
std::ostream& operator<<(std::ostream&, const date&);
|
|
|
|
#endif
|
2020-04-02 21:39:21 +00:00
|
|
|
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief A local time-of-day.
|
2020-04-10 16:46:00 +00:00
|
|
|
struct TOML_TRIVIAL_ABI time
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief The hour component, from 0 - 23.
|
2020-01-11 21:15:24 +00:00
|
|
|
uint8_t hour;
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief The minute component, from 0 - 59.
|
2020-01-11 21:15:24 +00:00
|
|
|
uint8_t minute;
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief The second component, from 0 - 59.
|
2020-01-11 21:15:24 +00:00
|
|
|
uint8_t second;
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief The fractional nanoseconds component, from 0 - 999999999.
|
2020-01-11 21:15:24 +00:00
|
|
|
uint32_t nanosecond;
|
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
/// \brief Equality operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator==(const time& lhs, const time& rhs) noexcept
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
2021-10-23 09:22:41 +00:00
|
|
|
return lhs.hour == rhs.hour && lhs.minute == rhs.minute && lhs.second == rhs.second
|
2020-01-11 21:15:24 +00:00
|
|
|
&& lhs.nanosecond == rhs.nanosecond;
|
|
|
|
}
|
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
/// \brief Inequality operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator!=(const time& lhs, const time& rhs) noexcept
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
2021-10-23 09:22:41 +00:00
|
|
|
private:
|
|
|
|
TOML_NODISCARD
|
2020-07-18 12:10:19 +00:00
|
|
|
TOML_ALWAYS_INLINE
|
2020-03-01 14:56:40 +00:00
|
|
|
static constexpr uint64_t pack(time t) noexcept
|
|
|
|
{
|
2021-10-23 09:22:41 +00:00
|
|
|
return static_cast<uint64_t>(t.hour) << 48 | static_cast<uint64_t>(t.minute) << 40
|
|
|
|
| static_cast<uint64_t>(t.second) << 32 | static_cast<uint64_t>(t.nanosecond);
|
2020-03-01 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 09:22:41 +00:00
|
|
|
public:
|
2020-03-01 14:56:40 +00:00
|
|
|
/// \brief Less-than operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator<(time lhs, time rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return pack(lhs) < pack(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Less-than-or-equal-to operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator<=(time lhs, time rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return pack(lhs) <= pack(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Greater-than operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator>(time lhs, time rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return pack(lhs) > pack(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Greater-than-or-equal-to operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator>=(time lhs, time rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return pack(lhs) >= pack(rhs);
|
|
|
|
}
|
2020-01-11 21:15:24 +00:00
|
|
|
};
|
|
|
|
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \brief Prints a time out to a stream as `HH:MM:SS.FFFFFF` (per RFC 3339).
|
|
|
|
/// \detail \cpp
|
2020-08-11 13:34:03 +00:00
|
|
|
/// std::cout << toml::time{ 10, 20, 34 } << "\n";
|
|
|
|
/// std::cout << toml::time{ 10, 20, 34, 500000000 } << "\n";
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \ecpp
|
2021-10-23 09:22:41 +00:00
|
|
|
///
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \out
|
|
|
|
/// 10:20:34
|
|
|
|
/// 10:20:34.5
|
|
|
|
/// \eout
|
2020-04-02 21:39:21 +00:00
|
|
|
template <typename Char>
|
2021-10-23 09:22:41 +00:00
|
|
|
inline std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>& lhs, const time& rhs)
|
2020-03-03 08:10:07 +00:00
|
|
|
{
|
|
|
|
impl::print_to_stream(rhs, lhs);
|
|
|
|
return lhs;
|
|
|
|
}
|
|
|
|
|
2021-10-23 09:22:41 +00:00
|
|
|
#if !defined(DOXYGEN) && !TOML_HEADER_ONLY
|
|
|
|
extern template TOML_API
|
|
|
|
std::ostream& operator<<(std::ostream&, const time&);
|
|
|
|
#endif
|
2020-04-02 21:39:21 +00:00
|
|
|
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief A timezone offset.
|
2020-04-10 16:46:00 +00:00
|
|
|
struct TOML_TRIVIAL_ABI time_offset
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief Offset from UTC+0, in minutes.
|
2020-01-11 21:15:24 +00:00
|
|
|
int16_t minutes;
|
|
|
|
|
2020-02-20 21:08:20 +00:00
|
|
|
/// \brief Default-constructs a zero time-offset.
|
|
|
|
TOML_NODISCARD_CTOR
|
2021-10-23 09:22:41 +00:00
|
|
|
constexpr time_offset() noexcept //
|
2020-02-20 21:08:20 +00:00
|
|
|
: minutes{}
|
|
|
|
{}
|
|
|
|
|
|
|
|
/// \brief Constructs a timezone offset from separate hour and minute totals.
|
2020-02-03 09:12:43 +00:00
|
|
|
///
|
|
|
|
/// \detail \cpp
|
2020-08-11 13:34:03 +00:00
|
|
|
/// std::cout << toml::time_offset{ 2, 30 } << "\n";
|
|
|
|
/// std::cout << toml::time_offset{ -2, 30 } << "\n";
|
|
|
|
/// std::cout << toml::time_offset{ -2, -30 } << "\n";
|
|
|
|
/// std::cout << toml::time_offset{ 0, 0 } << "\n";
|
2021-10-23 09:22:41 +00:00
|
|
|
///
|
2020-02-03 09:12:43 +00:00
|
|
|
/// \ecpp
|
2021-10-23 09:22:41 +00:00
|
|
|
///
|
2020-02-18 21:29:59 +00:00
|
|
|
/// \out
|
|
|
|
/// +02:30
|
|
|
|
/// -01:30
|
|
|
|
/// -02:30
|
|
|
|
/// Z
|
|
|
|
/// \eout
|
2021-10-23 09:22:41 +00:00
|
|
|
///
|
2020-02-29 20:34:08 +00:00
|
|
|
/// \param h The total hours.
|
|
|
|
/// \param m The total minutes.
|
2020-02-20 21:08:20 +00:00
|
|
|
TOML_NODISCARD_CTOR
|
2021-10-23 09:22:41 +00:00
|
|
|
constexpr time_offset(int8_t h, int8_t m) noexcept //
|
2020-02-29 20:34:08 +00:00
|
|
|
: minutes{ static_cast<int16_t>(h * 60 + m) }
|
2020-02-20 21:08:20 +00:00
|
|
|
{}
|
2020-01-11 21:15:24 +00:00
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
/// \brief Equality operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator==(time_offset lhs, time_offset rhs) noexcept
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
|
|
|
return lhs.minutes == rhs.minutes;
|
|
|
|
}
|
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
/// \brief Inequality operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator!=(time_offset lhs, time_offset rhs) noexcept
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
|
|
|
return lhs.minutes != rhs.minutes;
|
|
|
|
}
|
|
|
|
|
2020-03-01 14:56:40 +00:00
|
|
|
/// \brief Less-than operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator<(time_offset lhs, time_offset rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return lhs.minutes < rhs.minutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Less-than-or-equal-to operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator<=(time_offset lhs, time_offset rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return lhs.minutes <= rhs.minutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Greater-than operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator>(time_offset lhs, time_offset rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return lhs.minutes > rhs.minutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Greater-than-or-equal-to operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator>=(time_offset lhs, time_offset rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return lhs.minutes >= rhs.minutes;
|
|
|
|
}
|
2020-01-11 21:15:24 +00:00
|
|
|
};
|
|
|
|
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \brief Prints a time_offset out to a stream as `+-HH:MM or Z` (per RFC 3339).
|
|
|
|
/// \detail \cpp
|
2020-08-11 13:34:03 +00:00
|
|
|
/// std::cout << toml::time_offset{ 2, 30 } << "\n";
|
|
|
|
/// std::cout << toml::time_offset{ 2, -30 } << "\n";
|
|
|
|
/// std::cout << toml::time_offset{} << "\n";
|
|
|
|
/// std::cout << toml::time_offset{ -2, 30 } << "\n";
|
|
|
|
/// std::cout << toml::time_offset{ -2, -30 } << "\n";
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \ecpp
|
2021-10-23 09:22:41 +00:00
|
|
|
///
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \out
|
|
|
|
/// +02:30
|
|
|
|
/// +01:30
|
|
|
|
/// Z
|
|
|
|
/// -01:30
|
|
|
|
/// -02:30
|
|
|
|
/// \eout
|
2020-04-02 21:39:21 +00:00
|
|
|
template <typename Char>
|
2021-10-23 09:22:41 +00:00
|
|
|
inline std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>& lhs, const time_offset& rhs)
|
2020-03-03 08:10:07 +00:00
|
|
|
{
|
|
|
|
impl::print_to_stream(rhs, lhs);
|
|
|
|
return lhs;
|
|
|
|
}
|
|
|
|
|
2021-10-23 09:22:41 +00:00
|
|
|
#if !defined(DOXYGEN) && !TOML_HEADER_ONLY
|
|
|
|
extern template TOML_API
|
|
|
|
std::ostream& operator<<(std::ostream&, const time_offset&);
|
|
|
|
#endif
|
2020-04-02 21:39:21 +00:00
|
|
|
|
2021-05-06 08:03:25 +00:00
|
|
|
TOML_ABI_NAMESPACE_BOOL(TOML_HAS_CUSTOM_OPTIONAL_TYPE, custopt, stdopt);
|
2020-03-28 16:56:59 +00:00
|
|
|
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief A date-time.
|
2020-04-10 16:46:00 +00:00
|
|
|
struct date_time
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief The date component.
|
2020-01-11 21:15:24 +00:00
|
|
|
toml::date date;
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief The time component.
|
2020-01-11 21:15:24 +00:00
|
|
|
toml::time time;
|
2020-01-13 06:31:49 +00:00
|
|
|
/// \brief The timezone offset component.
|
2020-02-03 09:12:43 +00:00
|
|
|
///
|
2020-07-19 23:04:33 +00:00
|
|
|
/// \remarks The date_time is said to be 'local' if the offset is empty.
|
|
|
|
optional<toml::time_offset> offset;
|
2020-01-11 21:15:24 +00:00
|
|
|
|
2020-02-20 21:08:20 +00:00
|
|
|
/// \brief Default-constructs a zero date-time.
|
|
|
|
TOML_NODISCARD_CTOR
|
2021-10-23 09:22:41 +00:00
|
|
|
constexpr date_time() noexcept //
|
2020-02-20 21:08:20 +00:00
|
|
|
: date{},
|
2021-10-23 09:22:41 +00:00
|
|
|
time{},
|
|
|
|
offset{} // TINAE - icc bugfix
|
2020-02-20 21:08:20 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
/// \brief Constructs a local date-time.
|
|
|
|
///
|
|
|
|
/// \param d The date component.
|
|
|
|
/// \param t The time component.
|
|
|
|
TOML_NODISCARD_CTOR
|
2021-10-23 09:22:41 +00:00
|
|
|
constexpr date_time(toml::date d, toml::time t) noexcept //
|
2020-02-20 21:08:20 +00:00
|
|
|
: date{ d },
|
2021-10-23 09:22:41 +00:00
|
|
|
time{ t },
|
|
|
|
offset{} // TINAE - icc bugfix
|
2020-02-20 21:08:20 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
/// \brief Constructs an offset date-time.
|
|
|
|
///
|
|
|
|
/// \param d The date component.
|
|
|
|
/// \param t The time component.
|
2020-07-19 23:04:33 +00:00
|
|
|
/// \param off The timezone offset.
|
2020-02-20 21:08:20 +00:00
|
|
|
TOML_NODISCARD_CTOR
|
2021-10-23 09:22:41 +00:00
|
|
|
constexpr date_time(toml::date d, toml::time t, toml::time_offset off) noexcept
|
2020-02-20 21:08:20 +00:00
|
|
|
: date{ d },
|
2021-10-23 09:22:41 +00:00
|
|
|
time{ t },
|
|
|
|
offset{ off }
|
2020-02-20 21:08:20 +00:00
|
|
|
{}
|
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
/// \brief Returns true if this date_time does not contain timezone offset information.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
2020-01-11 21:15:24 +00:00
|
|
|
constexpr bool is_local() const noexcept
|
|
|
|
{
|
2020-07-19 23:04:33 +00:00
|
|
|
return !offset.has_value();
|
2020-01-11 21:15:24 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
/// \brief Equality operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator==(const date_time& lhs, const date_time& rhs) noexcept
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
2021-10-23 09:22:41 +00:00
|
|
|
return lhs.date == rhs.date && lhs.time == rhs.time && lhs.offset == rhs.offset;
|
2020-01-11 21:15:24 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
/// \brief Inequality operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator!=(const date_time& lhs, const date_time& rhs) noexcept
|
2020-01-11 21:15:24 +00:00
|
|
|
{
|
2020-03-01 14:56:40 +00:00
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Less-than operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator<(const date_time& lhs, const date_time& rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
if (lhs.date != rhs.date)
|
|
|
|
return lhs.date < rhs.date;
|
|
|
|
if (lhs.time != rhs.time)
|
|
|
|
return lhs.time < rhs.time;
|
2020-07-19 23:04:33 +00:00
|
|
|
return lhs.offset < rhs.offset;
|
2020-03-01 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Less-than-or-equal-to operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator<=(const date_time& lhs, const date_time& rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
if (lhs.date != rhs.date)
|
|
|
|
return lhs.date < rhs.date;
|
|
|
|
if (lhs.time != rhs.time)
|
|
|
|
return lhs.time < rhs.time;
|
2020-07-19 23:04:33 +00:00
|
|
|
return lhs.offset <= rhs.offset;
|
2020-03-01 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Greater-than operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator>(const date_time& lhs, const date_time& rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return !(lhs <= rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Greater-than-or-equal-to operator.
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_NODISCARD
|
|
|
|
friend constexpr bool operator>=(const date_time& lhs, const date_time& rhs) noexcept
|
2020-03-01 14:56:40 +00:00
|
|
|
{
|
|
|
|
return !(lhs < rhs);
|
2020-01-11 21:15:24 +00:00
|
|
|
}
|
|
|
|
};
|
2020-03-03 08:10:07 +00:00
|
|
|
|
2021-04-18 12:04:46 +00:00
|
|
|
TOML_ABI_NAMESPACE_END; // TOML_HAS_CUSTOM_OPTIONAL_TYPE
|
2020-03-28 16:56:59 +00:00
|
|
|
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \brief Prints a date_time out to a stream in RFC 3339 format.
|
|
|
|
/// \detail \cpp
|
2020-08-11 13:34:03 +00:00
|
|
|
/// std::cout << toml::date_time{ { 1987, 3, 16 }, { 10, 20, 34 } } << "\n";
|
|
|
|
/// std::cout << toml::date_time{ { 1987, 3, 16 }, { 10, 20, 34 }, { -2, -30 } } << "\n";
|
|
|
|
/// std::cout << toml::date_time{ { 1987, 3, 16 }, { 10, 20, 34 }, {} } << "\n";
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \ecpp
|
2021-10-23 09:22:41 +00:00
|
|
|
///
|
2020-03-03 08:10:07 +00:00
|
|
|
/// \out
|
|
|
|
/// 1987-03-16T10:20:34
|
|
|
|
/// 1987-03-16T10:20:34-02:30
|
|
|
|
/// 1987-03-16T10:20:34Z
|
|
|
|
/// \eout
|
2020-04-02 21:39:21 +00:00
|
|
|
template <typename Char>
|
2021-10-23 09:22:41 +00:00
|
|
|
inline std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>& lhs, const date_time& rhs)
|
2020-03-03 08:10:07 +00:00
|
|
|
{
|
|
|
|
impl::print_to_stream(rhs, lhs);
|
|
|
|
return lhs;
|
|
|
|
}
|
2020-04-02 21:39:21 +00:00
|
|
|
|
2021-10-23 09:22:41 +00:00
|
|
|
#if !defined(DOXYGEN) && !TOML_HEADER_ONLY
|
|
|
|
extern template TOML_API
|
|
|
|
std::ostream& operator<<(std::ostream&, const date_time&);
|
|
|
|
#endif
|
2020-01-11 21:15:24 +00:00
|
|
|
}
|
2021-04-18 12:04:46 +00:00
|
|
|
TOML_NAMESPACE_END;
|
2021-10-24 10:21:32 +00:00
|
|
|
|
|
|
|
#include "header_end.h"
|