# # # rename "unix/parse_time.cc" # to "unix/parse_date.cc" # # rename "win32/parse_time.cc" # to "win32/parse_date.cc" # # patch "Makefile.am" # from [96bcca654a9a94bc6155dae049f7378306ddc515] # to [2a42de1455a8d6a5b635bebab2f0965da83a95b4] # # patch "cmd_ws_commit.cc" # from [fecc82eb7710941c40551739e60a9387476ee036] # to [729a6ead62f91c4f1c8629938f15b5cfba69c5f4] # # patch "dates.cc" # from [7710859ebf8be74b9cab2baf645bf03e78f991c4] # to [602419695490292f43358e4cc93c24f294a46265] # # patch "platform.hh" # from [04a90e564b175d1193c25c2e59e9028ddefcc85d] # to [4b86bdcb86f3976266a0292855ef4da2ca313271] # # patch "unit-tests/dates.cc" # from [be9bcbe238f0221acb2c37f07b78f98b1a52471a] # to [cff226d0fad7b877ce95f1e14533379e7472f1d7] # # patch "unix/parse_date.cc" # from [b631a9eb2d3ac19ab6ec4f1339af6083b222e23d] # to [89bd1340c9f561a0bfa19a958abc73816efdafd7] # # patch "win32/parse_date.cc" # from [6108a9fd257df00911e28badf6c3acaf8ecc1e98] # to [ae91f326f46ee710cf86f8253d85324efc5483c0] # ============================================================ --- Makefile.am 96bcca654a9a94bc6155dae049f7378306ddc515 +++ Makefile.am 2a42de1455a8d6a5b635bebab2f0965da83a95b4 @@ -145,14 +145,14 @@ UNIX_PLATFORM_SOURCES = \ unix/process.cc unix/terminal.cc unix/inodeprint.cc \ unix/fs.cc unix/make_io_binary.cc unix/os_strerror.cc \ unix/cputime.cc unix/ssh_agent_platform.cc \ - unix/ssh_agent_platform.hh unix/parse_time.cc + unix/ssh_agent_platform.hh unix/parse_date.cc WIN32_PLATFORM_SOURCES = \ win32/read_password.cc win32/get_system_flavour.cc \ win32/process.cc win32/terminal.cc win32/inodeprint.cc \ win32/fs.cc win32/make_io_binary.cc win32/os_strerror.cc \ win32/cputime.cc win32/ssh_agent_platform.cc \ - win32/ssh_agent_platform.hh win32/parse_time.cc + win32/ssh_agent_platform.hh win32/parse_date.cc # these files (part of the main program) contain code subject to unit testing @@ -492,7 +492,7 @@ monotone-$(PACKAGE_VERSION)-setup.exe: m monotone-$(PACKAGE_VERSION)-setup.exe: mtn-stripped.exe html $(ALL_GMOFILES) linguas.iss dlls.iss monotone.iss $(ISCC) monotone.iss - + mtn-stripped.exe: mtn.exe strip $< -o $@ ============================================================ --- cmd_ws_commit.cc fecc82eb7710941c40551739e60a9387476ee036 +++ cmd_ws_commit.cc 729a6ead62f91c4f1c8629938f15b5cfba69c5f4 @@ -129,7 +129,7 @@ static bool }; static bool -date_fmt_valid (string date_fmt) +date_fmt_valid(string date_fmt) { if (date_fmt.empty()) { ============================================================ --- dates.cc 7710859ebf8be74b9cab2baf645bf03e78f991c4 +++ dates.cc 602419695490292f43358e4cc93c24f294a46265 @@ -444,8 +444,7 @@ date_t::from_formatted_localtime(string L(FL("parsing date '%s' with format '%s'") % s % fmt); // get local timezone values - E(parse_date(s, fmt, &tb), origin::user, - F("unable to parse date '%s' with format '%s'") % s % fmt); + parse_date(s, fmt, &tb); // strptime does *not* set the tm_isdst field in the broken down time // struct. setting it to -1 is apparently the way to tell mktime to ============================================================ --- platform.hh 04a90e564b175d1193c25c2e59e9028ddefcc85d +++ platform.hh 4b86bdcb86f3976266a0292855ef4da2ca313271 @@ -166,10 +166,10 @@ std::string get_locale_dir(); std::string get_locale_dir(); // Fill tp from s, using format fmt. -// Returns false on failure, true on success. +// throws on failure. // // This is strptime on Unix, something else on MinGW. -bool parse_date (const std::string s, const std::string fmt, struct tm *tp); +void parse_date(const std::string s, const std::string fmt, struct tm *tp); #endif // __PLATFORM_HH__ ============================================================ --- unit-tests/dates.cc be9bcbe238f0221acb2c37f07b78f98b1a52471a +++ unit-tests/dates.cc cff226d0fad7b877ce95f1e14533379e7472f1d7 @@ -312,6 +312,11 @@ UNIT_TEST(localtime_formats) //(date, "%a %d %b %Y %I:%M:%S %p %Z"); // the timezone label breaks this } + // check that trailing characters not matched by the date format are caught + UNIT_TEST_CHECK_THROW(date_t::from_formatted_localtime("1988-01-01 12:12:12 gobbledygook", + "%F %X"), + recoverable_failure); + #undef OK } #endif ============================================================ --- unix/parse_time.cc b631a9eb2d3ac19ab6ec4f1339af6083b222e23d +++ unix/parse_date.cc 89bd1340c9f561a0bfa19a958abc73816efdafd7 @@ -8,12 +8,26 @@ // PURPOSE. #include "base.hh" +#include "sanity.hh" +#include "origin_type.hh" + #include -bool parse_date (const std::string s, const std::string fmt, struct tm *tp) +void parse_date(const std::string s, const std::string fmt, struct tm *tp) { char *p = strptime(s.c_str(), fmt.c_str(), tp); - return p != 0; + E(p, origin::user,// failed to match all of the fromat string + F("unable to parse date '%s' with format '%s'") % s % fmt); + + E(*p == 0, origin::user, // extraneous characters in input string + F("invalid date '%s' not matched by format '%s'") % s % fmt); } -// end of file + +// Local Variables: +// mode: C++ +// fill-column: 76 +// c-file-style: "gnu" +// indent-tabs-mode: nil +// End: +// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: ============================================================ --- win32/parse_time.cc 6108a9fd257df00911e28badf6c3acaf8ecc1e98 +++ win32/parse_date.cc ae91f326f46ee710cf86f8253d85324efc5483c0 @@ -9,13 +9,20 @@ #include "base.hh" -bool parse_date (const std::string s, const std::string fmt, struct tm *tp) +void parse_date(const std::string s, const std::string fmt, struct tm *tp) { // Apparently the Win32 API does not provide a date parsing function. // // So far, parse_date is only used in the changelog processing to // allow the user to change the date cert. So we just disable that // on Win32; see cmd_ws_commit.cc get_log_message_interactively. - return false; + E(false, origin::system, F("date parsing not available on win32")); } -// end of file + +// Local Variables: +// mode: C++ +// fill-column: 76 +// c-file-style: "gnu" +// indent-tabs-mode: nil +// End: +// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: