diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-05-05 23:59:31 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-05-06 00:01:28 +0100 |
commit | 0a967cebf1526c0beba12deef8756e12eaeb9472 (patch) | |
tree | 20eaaa3476e1d984b79bef53811cf58b428fce9c | |
parent | Explicitly add now deprecated implicit copy operator to VariableType (diff) | |
download | project2-0a967cebf1526c0beba12deef8756e12eaeb9472.tar.bz2 project2-0a967cebf1526c0beba12deef8756e12eaeb9472.tar.xz project2-0a967cebf1526c0beba12deef8756e12eaeb9472.zip |
Add generic duration based time_pointer to time_t converterproject2-1.3.3.2
-rw-r--r-- | project2/common/chronoHelpers.h | 12 | ||||
-rw-r--r-- | project2/files/optionsSource.cpp | 3 | ||||
-rw-r--r-- | project2/xml/xmlScriptParser.cpp | 7 |
3 files changed, 18 insertions, 4 deletions
diff --git a/project2/common/chronoHelpers.h b/project2/common/chronoHelpers.h new file mode 100644 index 0000000..7bf1650 --- /dev/null +++ b/project2/common/chronoHelpers.h @@ -0,0 +1,12 @@ +#ifndef COMMON_CHRONOHELPERS_H +#define COMMON_CHRONOHELPERS_H + +template<typename time_point> +std::time_t +to_time_t(const time_point & t) +{ + return std::chrono::duration_cast<std::chrono::seconds>(t.time_since_epoch()).count(); +} + +#endif + diff --git a/project2/files/optionsSource.cpp b/project2/files/optionsSource.cpp index 9172834..7d81e50 100644 --- a/project2/files/optionsSource.cpp +++ b/project2/files/optionsSource.cpp @@ -6,6 +6,7 @@ #include "configFlexLexer.h" #include <boost/shared_ptr.hpp> #include <fstream> +#include <chronoHelpers.h> FileOptions::FileOptions(const std::filesystem::path & f) : file(std::filesystem::absolute(f)) @@ -29,7 +30,7 @@ boost::posix_time::ptime FileOptions::modifiedTime() const { return boost::posix_time::from_time_t( - std::chrono::system_clock::to_time_t( + to_time_t( std::filesystem::exists(file) ? std::max( std::filesystem::last_write_time(file), diff --git a/project2/xml/xmlScriptParser.cpp b/project2/xml/xmlScriptParser.cpp index 7e4565b..354bb55 100644 --- a/project2/xml/xmlScriptParser.cpp +++ b/project2/xml/xmlScriptParser.cpp @@ -4,6 +4,7 @@ #include "commonObjects.h" #include "variables/literal.h" #include <filesystem> +#include <chronoHelpers.h> static const std::string XIncludeNS("http://www.w3.org/2001/XInclude"); static const std::string XIncludeInclude("include"); @@ -17,7 +18,7 @@ XmlScriptParser::XmlScriptParser(const std::filesystem::path & file) throw NotReadable(file.string()); } doIncludes(get_document()->get_root_node(), file); - files.insert(Files::value_type(file, std::chrono::system_clock::to_time_t( + files.insert(Files::value_type(file, to_time_t( std::filesystem::last_write_time(file)))); } @@ -38,7 +39,7 @@ XmlScriptParser::doIncludes(xmlpp::Element * e, const std::filesystem::path & f) xmlpp::DomParser(inc.string()).get_document()->get_root_node()))) { doIncludes(c, inc); } - files.insert(Files::value_type(inc, std::chrono::system_clock::to_time_t( + files.insert(Files::value_type(inc, to_time_t( std::filesystem::last_write_time(inc)))); } else { @@ -79,7 +80,7 @@ XmlScriptParser::isCurrent() const { for (const Files::value_type & f : files) { try { - if (std::chrono::system_clock::to_time_t(std::filesystem::last_write_time(f.first)) != f.second) { + if (to_time_t(std::filesystem::last_write_time(f.first)) != f.second) { _root.reset(); return false; } |