From a1218b266aedf0a7bee9448ee58d84f87823095e Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 7 May 2017 13:50:53 +0900 Subject: [PATCH] add restriction to datetime offset size --- toml/datetime.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/toml/datetime.hpp b/toml/datetime.hpp index 88bb821..23f53b3 100644 --- a/toml/datetime.hpp +++ b/toml/datetime.hpp @@ -117,9 +117,12 @@ basic_datetime::basic_datetime(std::chrono::system_clock::time_point tp) >(diff).count() % 1000; std::tm *utc = std::gmtime(&t); - - offset_hour = this->hour - utc->tm_hour; - offset_minute = this->minute - utc->tm_min; + int total_offset = (this->hour - utc->tm_hour) * 60 + + (this->minute - utc->tm_min); + if(total_offset > 720) total_offset -= 1440; + else if(total_offset < -720) total_offset += 1440; + offset_hour = total_offset / 60; + offset_minute = total_offset - (offset_hour * 60); } template