reapack

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

commit 2919309037e348343f013b03a9e0dfa9b8433fdb
parent f601f79346b8ebc2f96ac8da6836674de62b4bf5
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu, 11 Feb 2016 21:50:20 -0500

display the release date in the package version history

Diffstat:
Msrc/about.cpp | 4++++
Msrc/index_v1.cpp | 3+++
Msrc/version.cpp | 26+++++++++++++++++++++++++-
Msrc/version.hpp | 6++++++
Mtest/index_v1.cpp | 14++++++++++++++
Atest/indexes/v1/ReaPack/time.xml | 9+++++++++
Mtest/version.cpp | 27+++++++++++++++++++++++++++
7 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/src/about.cpp b/src/about.cpp @@ -298,6 +298,10 @@ void History::fillReport() if(!ver->author().empty()) stream() << " by " << ver->author(); + const string &date = ver->formattedDate(); + if(!date.empty()) + stream() << " – " << date; + stream() << NL; const string &changelog = ver->changelog(); diff --git a/src/index_v1.cpp b/src/index_v1.cpp @@ -142,6 +142,9 @@ void LoadVersionV1(TiXmlElement *verNode, Package *pkg) const char *author = verNode->Attribute("author"); if(author) ver->setAuthor(author); + const char *time = verNode->Attribute("time"); + if(time) ver->setTime(time); + TiXmlElement *node = verNode->FirstChildElement("source"); while(node) { diff --git a/src/version.cpp b/src/version.cpp @@ -27,7 +27,7 @@ using namespace std; Version::Version(const std::string &str, Package *pkg) - : m_name(str), m_code(0), m_package(pkg), m_mainSource(nullptr) + : m_name(str), m_code(0), m_time(), m_package(pkg), m_mainSource(nullptr) { static const regex pattern("(\\d+)"); @@ -109,6 +109,30 @@ void Version::setChangelog(const std::string &changelog) m_changelog = changelog; } +void Version::setTime(const char *iso8601) +{ + unsigned int year, month, day; + size_t n = sscanf(iso8601, "%u-%u-%u", &year, &month, &day); + + if(n < 3) + return; + + m_time = {}; + m_time.tm_year = year - 1900; + m_time.tm_mon = month - 1; + m_time.tm_mday = day; +} + +string Version::formattedDate() const +{ + if(m_time.tm_year == 0) + return {}; + + char buf[32] = {}; + strftime(buf, sizeof(buf), "%B %d %Y", &m_time); + return buf; +} + const Source *Version::source(const size_t index) const { auto it = m_sources.begin(); diff --git a/src/version.hpp b/src/version.hpp @@ -19,6 +19,7 @@ #define REAPACK_VERSION_HPP #include <cstdint> +#include <ctime> #include <set> #include <string> @@ -40,6 +41,10 @@ public: void setAuthor(const std::string &author) { m_author = author; } const std::string &author() const { return m_author; } + void setTime(const char *iso8601); + const std::tm &time() const { return m_time; } + std::string formattedDate() const; + void setChangelog(const std::string &); const std::string &changelog() const { return m_changelog; } @@ -57,6 +62,7 @@ public: private: std::string m_name; uint64_t m_code; + std::tm m_time; const Package *m_package; const Source *m_mainSource; diff --git a/test/index_v1.cpp b/test/index_v1.cpp @@ -80,6 +80,20 @@ TEST_CASE("read version author", M) { == "Watanabe Saki"); } +TEST_CASE("read version time", M) { + UseRootPath root(RIPATH); + + const RemoteIndex *ri = RemoteIndex::load("time"); + RIPTR(ri); + + CHECK(ri->packages().size() == 1); + + const tm &time = ri->category(0)->package(0)->lastVersion()->time(); + REQUIRE(time.tm_year == 2016 - 1900); + REQUIRE(time.tm_mon == 2 - 1); + REQUIRE(time.tm_mday == 12); +} + TEST_CASE("invalid version tag", M) { UseRootPath root(RIPATH); diff --git a/test/indexes/v1/ReaPack/time.xml b/test/indexes/v1/ReaPack/time.xml @@ -0,0 +1,9 @@ +<index version="1"> + <category name="catname"> + <reapack name="packname" type="script"> + <version name="1.0" time="2016-02-12T01:16:40Z"> + <source platform="all" file="filename">https://google.com/</source> + </version> + </reapack> + </category> +</index> diff --git a/test/version.cpp b/test/version.cpp @@ -193,6 +193,33 @@ TEST_CASE("version author", M) { REQUIRE(ver.author() == "cfillion"); } +TEST_CASE("version date", M) { + Version ver("1.0"); + CHECK(ver.time().tm_year == 0); + CHECK(ver.time().tm_mon == 0); + CHECK(ver.time().tm_mday == 0); + CHECK(ver.formattedDate() == ""); + + SECTION("valid") { + ver.setTime("2016-02-12T01:16:40Z"); + REQUIRE(ver.time().tm_year == 2016 - 1900); + REQUIRE(ver.time().tm_mon == 2 - 1); + REQUIRE(ver.time().tm_mday == 12); + REQUIRE(ver.formattedDate() != ""); + } + + SECTION("garbage") { + ver.setTime("hello world"); + REQUIRE(ver.time().tm_year == 0); + REQUIRE(ver.formattedDate() == ""); + } + + SECTION("out of range") { + ver.setTime("2016-99-99T99:99:99Z"); + ver.formattedDate(); // no crash + } +} + #ifdef __APPLE__ TEST_CASE("drop windows sources on os x", M) { MAKE_VERSION