mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 09:08:08 +08:00
fix datetime conversion
use internal duration type in std::chrono::system_clock::time_point
This commit is contained in:
@@ -353,9 +353,13 @@ struct local_datetime
|
|||||||
|
|
||||||
operator std::chrono::system_clock::time_point() const
|
operator std::chrono::system_clock::time_point() const
|
||||||
{
|
{
|
||||||
|
using internal_duration =
|
||||||
|
typename std::chrono::system_clock::time_point::duration;
|
||||||
// std::mktime returns date as local time zone. no conversion needed
|
// std::mktime returns date as local time zone. no conversion needed
|
||||||
return std::chrono::system_clock::time_point(this->date) +
|
auto dt = std::chrono::system_clock::time_point(this->date);
|
||||||
std::chrono::nanoseconds(this->time);
|
dt += std::chrono::duration_cast<internal_duration>(
|
||||||
|
std::chrono::nanoseconds(this->time));
|
||||||
|
return dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator std::time_t() const
|
operator std::time_t() const
|
||||||
@@ -435,9 +439,12 @@ struct offset_datetime
|
|||||||
operator std::chrono::system_clock::time_point() const
|
operator std::chrono::system_clock::time_point() const
|
||||||
{
|
{
|
||||||
// get date-time
|
// get date-time
|
||||||
|
using internal_duration =
|
||||||
|
typename std::chrono::system_clock::time_point::duration;
|
||||||
std::chrono::system_clock::time_point tp =
|
std::chrono::system_clock::time_point tp =
|
||||||
std::chrono::system_clock::time_point(this->date) +
|
std::chrono::system_clock::time_point(this->date) +
|
||||||
std::chrono::nanoseconds(this->time);
|
std::chrono::duration_cast<internal_duration>(
|
||||||
|
std::chrono::nanoseconds(this->time));
|
||||||
|
|
||||||
// get date-time in UTC. let's say we are in +09:00 (JPN).
|
// get date-time in UTC. let's say we are in +09:00 (JPN).
|
||||||
// writing 12:00:00 in +09:00 means 03:00:00Z. to represent
|
// writing 12:00:00 in +09:00 means 03:00:00Z. to represent
|
||||||
|
Reference in New Issue
Block a user