From 91588c7e96913629cd0e8560438c7ed440e59c8a Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 26 Sep 2015 13:29:31 -0400 Subject: [PATCH] ISO8601: Added static ::dayOfWeek --- src/ISO8601.cpp | 19 +++++++++++++++++++ src/ISO8601.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/ISO8601.cpp b/src/ISO8601.cpp index 0179b2789..014d579ca 100644 --- a/src/ISO8601.cpp +++ b/src/ISO8601.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #define DAY 86400 @@ -796,6 +797,24 @@ bool ISO8601p::parse (const std::string& input, std::string::size_type& start) return false; } +//////////////////////////////////////////////////////////////////////////////// +// Static +int ISO8601d::dayOfWeek (const std::string& input) +{ + if (ISO8601d::minimumMatchLength== 0) + minimumMatchLength= 3; + + if (closeEnough (STRING_DATE_SUNDAY, input, minimumMatchLength)) return 0; + else if (closeEnough (STRING_DATE_MONDAY, input, minimumMatchLength)) return 1; + else if (closeEnough (STRING_DATE_TUESDAY, input, minimumMatchLength)) return 2; + else if (closeEnough (STRING_DATE_WEDNESDAY, input, minimumMatchLength)) return 3; + else if (closeEnough (STRING_DATE_THURSDAY, input, minimumMatchLength)) return 4; + else if (closeEnough (STRING_DATE_FRIDAY, input, minimumMatchLength)) return 5; + else if (closeEnough (STRING_DATE_SATURDAY, input, minimumMatchLength)) return 6; + + return -1; +} + //////////////////////////////////////////////////////////////////////////////// void ISO8601p::clear () { diff --git a/src/ISO8601.h b/src/ISO8601.h index 80aeabc8f..b6df2aed4 100644 --- a/src/ISO8601.h +++ b/src/ISO8601.h @@ -44,6 +44,8 @@ public: operator time_t () const; bool parse (const std::string&, std::string::size_type&, const std::string& format = ""); + static int dayOfWeek (const std::string&); + private: void clear (); bool parse_date_time (Nibbler&);