diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-06-01 13:22:08 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-06-01 13:22:08 +0100 |
commit | 7fd20c4f63a534d8266e088a830cb9e0624632e7 (patch) | |
tree | 7b02c07e0deb5c1d55a8831a37b5f24f5e51c407 | |
parent | Include parser state on lexer match failure (diff) | |
download | gentoobrowse-api-7fd20c4f63a534d8266e088a830cb9e0624632e7.tar.bz2 gentoobrowse-api-7fd20c4f63a534d8266e088a830cb9e0624632e7.tar.xz gentoobrowse-api-7fd20c4f63a534d8266e088a830cb9e0624632e7.zip |
Fix date only conversions in news model.
Impement packPqTextArray
-rw-r--r-- | gentoobrowse-api/domain/portage-models.ice | 2 | ||||
-rw-r--r-- | gentoobrowse-api/service/converters.cpp | 23 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/testPortage.cpp | 10 |
3 files changed, 27 insertions, 8 deletions
diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice index f281aea..570408c 100644 --- a/gentoobrowse-api/domain/portage-models.ice +++ b/gentoobrowse-api/domain/portage-models.ice @@ -67,7 +67,7 @@ module Gentoo { ["slicer:db:pkey"] string newsid; string title; - [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ] + [ "slicer:conversion:boost.posix_time.ptime:posixTimeToShortDate:shortDateToPosixTime" ] string posted; [ "slicer:conversion:std.string:unpackPqTextArray:packPqTextArray" ] StringList body; diff --git a/gentoobrowse-api/service/converters.cpp b/gentoobrowse-api/service/converters.cpp index b0ffacf..e8b19f5 100644 --- a/gentoobrowse-api/service/converters.cpp +++ b/gentoobrowse-api/service/converters.cpp @@ -1,6 +1,7 @@ #include <portage-models.h> #include "unpackPqTextArray.h" #include <string> +#include <boost/algorithm/string/join.hpp> namespace Slicer { ::Gentoo::StringList @@ -14,9 +15,27 @@ namespace Slicer { } std::string - packPqTextArray(const ::Gentoo::StringList &) + packPqTextArray(const ::Gentoo::StringList & l) { - return std::string(); + if (l.empty()) return "{}"; + ::Gentoo::StringList l2(l); + for(auto & i : l2) { + boost::algorithm::replace_all(i, "\"", "\\\""); + i = "\"" + i + "\""; + } + return "{" + boost::algorithm::join(l2, ",") + "}"; + } + + boost::posix_time::ptime + shortDateToPosixTime(const std::string & s) + { + return boost::posix_time::ptime(boost::gregorian::from_simple_string(s)); + } + + std::string + posixTimeToShortDate(const boost::posix_time::ptime & s) + { + return boost::gregorian::to_sql_string(s.date()); } } diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index 3b51df7..7eb449a 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -201,7 +201,7 @@ BOOST_AUTO_TEST_CASE( getNewsItem ) BOOST_REQUIRE(n); BOOST_REQUIRE_EQUAL("2015-02-01-use-libav", n->newsid); BOOST_REQUIRE_EQUAL("ffmpeg/libav conflict management: USE=libav", n->title); - BOOST_REQUIRE_EQUAL("2015-02-01T00:00:00", n->posted); + BOOST_REQUIRE_EQUAL("2015-02-01", n->posted); BOOST_REQUIRE(n->authorname); BOOST_REQUIRE_EQUAL("Michał Górny", *n->authorname); BOOST_REQUIRE(n->authoremail); @@ -227,16 +227,16 @@ BOOST_AUTO_TEST_CASE( getNewsSearch ) BOOST_REQUIRE_EQUAL(5, ns.size()); BOOST_REQUIRE_EQUAL("Or you might see linkage failures with \"std::__cxx11::string\" in the output.", ns.front()->body[1]); BOOST_REQUIRE_EQUAL("These are signs that you need to rebuild packages using the new C++ ABI. You can quickly do so by using revdep-rebuild (from gentoolkit) like so: # revdep-rebuild --library 'libstdc\\+\\+\\.so\\.6' -- --exclude gcc", ns.front()->body[2]); - BOOST_REQUIRE_EQUAL("2015-10-22T00:00:00", ns.front()->posted); - BOOST_REQUIRE_EQUAL("2009-01-04T00:00:00", ns.back()->posted); + BOOST_REQUIRE_EQUAL("2015-10-22", ns.front()->posted); + BOOST_REQUIRE_EQUAL("2009-01-04", ns.back()->posted); } BOOST_AUTO_TEST_CASE( getNewsRecent ) { auto ns = p->getNewsRecent(3); BOOST_REQUIRE_EQUAL(3, ns.size()); - BOOST_REQUIRE_EQUAL("2015-10-22T00:00:00", ns.front()->posted); - BOOST_REQUIRE_EQUAL("2015-10-07T00:00:00", ns.back()->posted); + BOOST_REQUIRE_EQUAL("2015-10-22", ns.front()->posted); + BOOST_REQUIRE_EQUAL("2015-10-07", ns.back()->posted); } BOOST_AUTO_TEST_SUITE_END(); |