>From a99ff1dba347c1d5059316c9d3b3d2c5f548a711 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 15 Dec 2014 00:06:31 +0100 Subject: [PATCH] Add a new --prospicience command line option. This option allows to change the date used for the authenticity checks and allows to verify that the program works correctly at a future (for testing releases before actually releasing them) or past (for reproducing problems) dates. --- authenticity.cpp | 6 +++++- global_settings.cpp | 10 ++++++++++ global_settings.hpp | 16 ++++++++++------ skeleton.cpp | 48 +++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/authenticity.cpp b/authenticity.cpp index 4c96ed1..e6d64c5 100644 --- a/authenticity.cpp +++ b/authenticity.cpp @@ -275,8 +275,12 @@ void authenticate_system() return; } + calendar_date const + prospicience_date = global_settings::instance().prospicience_date(); std::string const diagnostic_message = Authenticity::Assay - (calendar_date() + (prospicience_date == last_yyyy_date() + ? today() + : prospicience_date ,global_settings::instance().data_directory() ); if diff --git a/global_settings.cpp b/global_settings.cpp index 835f9ac..8e32bdf 100644 --- a/global_settings.cpp +++ b/global_settings.cpp @@ -55,6 +55,7 @@ ,custom_io_0_ (false) ,regression_testing_ (false) ,data_directory_ (fs::system_complete(".")) + ,prospicience_date_ (last_yyyy_date()) {} global_settings::~global_settings() @@ -111,6 +112,11 @@ void global_settings::set_data_directory(std::string const& s) data_directory_ = fs::system_complete(s); } +void global_settings::set_prospicience_date(calendar_date const& d) +{ + prospicience_date_ = d; +} + bool global_settings::mellon() const { return mellon_; @@ -141,3 +147,7 @@ bool global_settings::regression_testing() const return data_directory_; } +calendar_date const& global_settings::prospicience_date() const +{ + return prospicience_date_; +} diff --git a/global_settings.hpp b/global_settings.hpp index 698b3b4..0ed6196 100644 --- a/global_settings.hpp +++ b/global_settings.hpp @@ -26,6 +26,7 @@ #include "config.hpp" +#include "calendar_date.hpp" #include "obstruct_slicing.hpp" #include "so_attributes.hpp" #include "uncopyable_lmi.hpp" @@ -80,13 +81,15 @@ class LMI_SO global_settings void set_custom_io_0 (bool); void set_regression_testing (bool); void set_data_directory (std::string const&); + void set_prospicience_date (calendar_date const&); - bool mellon () const; - bool ash_nazg () const; - std::string const& pyx () const; - bool custom_io_0 () const; - bool regression_testing () const; - fs::path const& data_directory () const; + bool mellon () const; + bool ash_nazg () const; + std::string const& pyx () const; + bool custom_io_0 () const; + bool regression_testing () const; + fs::path const& data_directory () const; + calendar_date const& prospicience_date () const; private: global_settings(); @@ -97,6 +100,7 @@ class LMI_SO global_settings bool custom_io_0_; bool regression_testing_; fs::path data_directory_; + calendar_date prospicience_date_; #ifdef __BORLANDC__ // COMPILER !! Borland compilers defectively [11/5] require a public dtor; see: diff --git a/skeleton.cpp b/skeleton.cpp index 94279c2..b1822dd 100644 --- a/skeleton.cpp +++ b/skeleton.cpp @@ -42,6 +42,7 @@ #include "alert.hpp" #include "assert_lmi.hpp" #include "authenticity.hpp" +#include "calendar_date.hpp" #include "census_document.hpp" #include "census_view.hpp" #include "configurable_settings.hpp" @@ -90,10 +91,12 @@ #include #include #include +#include #include // wxIsDebuggerRunning() #include #include #include // wxSafeShowMessage() +#include // wxRound() #include #include #include @@ -1198,15 +1201,16 @@ bool Skeleton::ProcessCommandLine(int argc, char* argv[]) // TRICKY !! Some long options are aliased to unlikely octal values. static Option long_options[] = { - {"ash_nazg" ,NO_ARG ,0 ,001 ,0 ,"ash nazg durbatulûk"}, - {"ash_naz" ,NO_ARG ,0 ,003 ,0 ,"fraud"}, - {"help" ,NO_ARG ,0 ,'h' ,0 ,"display this help and exit"}, - {"mellon" ,NO_ARG ,0 ,002 ,0 ,"pedo mellon a minno"}, - {"mello" ,NO_ARG ,0 ,003 ,0 ,"fraud"}, - {"pyx" ,REQD_ARG ,0 ,'x' ,0 ,"for docimasy"}, - {"data_path" ,REQD_ARG ,0 ,'d' ,0 ,"path to data files"}, - {"print_db" ,NO_ARG ,0 ,'p' ,0 ,"print product databases"}, - {0 ,NO_ARG ,0 ,0 ,0 ,""} + {"ash_nazg" ,NO_ARG ,0 ,001 ,0 ,"ash nazg durbatulûk"}, + {"ash_naz" ,NO_ARG ,0 ,003 ,0 ,"fraud"}, + {"help" ,NO_ARG ,0 ,'h' ,0 ,"display this help and exit"}, + {"mellon" ,NO_ARG ,0 ,002 ,0 ,"pedo mellon a minno"}, + {"mello" ,NO_ARG ,0 ,003 ,0 ,"fraud"}, + {"pyx" ,REQD_ARG ,0 ,'x' ,0 ,"for docimasy"}, + {"data_path" ,REQD_ARG ,0 ,'d' ,0 ,"path to data files"}, + {"print_db" ,NO_ARG ,0 ,'p' ,0 ,"print product databases"}, + {"prospicience" ,REQD_ARG ,0 ,004 ,0 ,"validation date"}, + {0 ,NO_ARG ,0 ,0 ,0 ,""} }; bool show_help = false; @@ -1238,6 +1242,32 @@ bool Skeleton::ProcessCommandLine(int argc, char* argv[]) } break; + case 004: + { + wxString const date_string(getopt_long.optarg); + wxDateTime dt; + wxString::const_iterator date_end; + if( !dt.ParseFormat(date_string, "%Y%m%d", &date_end) + || date_end != date_string.end() + ) + { + warning() << "Invalid prospicience option value '" + << date_string + << "' (must be in YYYYMMDD format)." + << std::flush + ; + } + else + { + // wxDateTime JDN corresponds to the noon, not the + // midnight, and so requires half a day adjustment. + global_settings::instance().set_prospicience_date + (calendar_date(jdn_t(wxRound(dt.GetJDN() + 0.5))) + ); + } + } + break; + case 'd': { global_settings::instance().set_data_directory -- 1.7.9