reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit c63c076fee9836d7644af333000a6b90ac59703d
parent 2bea14d1b31891de1ae76542f5dc56721dad7e74
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 19 Jun 2016 22:55:35 -0400

version: refactor time parsing code

Diffstat:
Msrc/version.cpp | 14++++++--------
Mtest/version.cpp | 2+-
2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/version.cpp b/src/version.cpp @@ -23,6 +23,7 @@ #include <boost/lexical_cast.hpp> #include <cctype> +#include <iomanip> #include <regex> using namespace std; @@ -137,16 +138,13 @@ void Version::setChangelog(const string &changelog) void Version::setTime(const char *iso8601) { - unsigned int year, month, day; - size_t n = sscanf(iso8601, "%u-%u-%u", &year, &month, &day); + tm time = {}; - if(n < 3 || year < 1900 || month < 1 || month > 12 || day < 1 || day > 31) - return; + istringstream stream(iso8601); + stream >> std::get_time(&time, "%Y-%m-%d"); - m_time = {}; - m_time.tm_year = year - 1900; - m_time.tm_mon = month - 1; - m_time.tm_mday = day; + if(stream.good()) + swap(m_time, time); } string Version::displayTime() const diff --git a/test/version.cpp b/test/version.cpp @@ -338,7 +338,7 @@ TEST_CASE("version date", M) { SECTION("out of range") { ver.setTime("2016-99-99T99:99:99Z"); - ver.displayTime(); // no crash + REQUIRE(ver.displayTime() == ""); } }