From 68c6afbdd4705198857dd7f0be244c4f4fcd55d6 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 26 Sep 2015 23:08:29 -0400 Subject: [PATCH] ISO8601d: Conversion from Date to ISO8601d --- src/Nibbler.cpp | 9 +++++---- src/columns/ColUDA.cpp | 8 +++----- src/commands/CmdCalendar.cpp | 38 ++++++++++++++++++------------------ src/commands/CmdHistory.cpp | 3 ++- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Nibbler.cpp b/src/Nibbler.cpp index b2d020f28..e025c6d42 100644 --- a/src/Nibbler.cpp +++ b/src/Nibbler.cpp @@ -32,6 +32,7 @@ #include #include #ifdef NIBBLER_FEATURE_DATE +#include #include #endif #ifdef NIBBLER_FEATURE_REGEX @@ -818,8 +819,8 @@ bool Nibbler::getDate (const std::string& format, time_t& t) ! Lexer::isDigit ((*_input)[i + 1]) && ! Lexer::isDigit ((*_input)[i + 2])) { - wday = Date::dayOfWeek (_input->substr (i, 3).c_str ()); - i += (format[f] == 'a') ? 3 : Date::dayName (wday).size (); + wday = ISO8601d::dayOfWeek (_input->substr (i, 3).c_str ()); + i += (format[f] == 'a') ? 3 : ISO8601d::dayName (wday).size (); } else return false; @@ -834,8 +835,8 @@ bool Nibbler::getDate (const std::string& format, time_t& t) { if (month != -1) return false; - month = Date::monthOfYear (_input->substr (i, 3).c_str()); - i += (format[f] == 'b') ? 3 : Date::monthName (month).size (); + month = ISO8601d::monthOfYear (_input->substr (i, 3).c_str()); + i += (format[f] == 'b') ? 3 : ISO8601d::monthName (month).size (); } else return false; diff --git a/src/columns/ColUDA.cpp b/src/columns/ColUDA.cpp index 05ab86429..45c9d69f7 100644 --- a/src/columns/ColUDA.cpp +++ b/src/columns/ColUDA.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -89,14 +88,14 @@ void ColumnUDA::measure (Task& task, unsigned int& minimum, unsigned int& maximu // rc.report..dateformat // rc.dateformat.report // rc.dateformat - Date date ((time_t) strtol (value.c_str (), NULL, 10)); + ISO8601d date ((time_t) strtol (value.c_str (), NULL, 10)); std::string format = context.config.get ("report." + _report + ".dateformat"); if (format == "") format = context.config.get ("dateformat.report"); if (format == "") format = context.config.get ("dateformat"); - minimum = maximum = Date::length (format); + minimum = maximum = ISO8601d::length (format); } else if (_type == "duration") { @@ -153,8 +152,7 @@ void ColumnUDA::render ( lines.push_back ( color.colorize ( leftJustify ( - Date ((time_t) strtol (value.c_str (), NULL, 10)) - .toString (format), width))); + ISO8601d ((time_t) strtol (value.c_str (), NULL, 10)).toString (format), width))); } else if (_type == "duration") { diff --git a/src/commands/CmdCalendar.cpp b/src/commands/CmdCalendar.cpp index d137daa3a..b294f89fa 100644 --- a/src/commands/CmdCalendar.cpp +++ b/src/commands/CmdCalendar.cpp @@ -99,7 +99,7 @@ int CmdCalendar::execute (std::string& output) // Set up a vector of months, for autoComplete. std::vector monthNames; for (int i = 1; i <= 12; ++i) - monthNames.push_back (lowerCase (Date::monthName (i))); + monthNames.push_back (lowerCase (ISO8601d::monthName (i))); // For autoComplete results. std::vector matches; @@ -140,7 +140,7 @@ int CmdCalendar::execute (std::string& output) // "January" etc. else if (autoComplete (lowerCase (arg), monthNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1) { - argMonth = Date::monthOfYear (matches[0]); + argMonth = ISO8601d::monthOfYear (matches[0]); if (argMonth == -1) throw format (STRING_CMD_CAL_BAD_MONTH, arg); } @@ -235,7 +235,7 @@ int CmdCalendar::execute (std::string& output) // Print month headers (cheating on the width settings, yes) for (int i = 0 ; i < monthsPerLine ; i++) { - std::string month = Date::monthName (nextM); + std::string month = ISO8601d::monthName (nextM); // 12345678901234567890123456 = 26 chars wide // ^^ = center @@ -426,7 +426,7 @@ std::string CmdCalendar::renderMonths ( int monthsPerLine) { // What day of the week does the user consider the first? - int weekStart = Date::dayOfWeek (context.config.get ("weekstart")); + int weekStart = ISO8601d::dayOfWeek (context.config.get ("weekstart")); if (weekStart != 0 && weekStart != 1) throw std::string (STRING_CMD_CAL_SUN_MON); @@ -441,24 +441,24 @@ std::string CmdCalendar::renderMonths ( if (weekStart == 1) { view.add (Column::factory ("string.right", " ")); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (1), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (2), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (3), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (4), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (5), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (6), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (0), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (1), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (2), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (3), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (4), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (5), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (6), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (0), 0, 2))); } else { view.add (Column::factory ("string.right", " ")); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (0), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (1), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (2), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (3), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (4), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (5), 0, 2))); - view.add (Column::factory ("string.right", utf8_substr (Date::dayName (6), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (0), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (1), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (2), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (3), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (4), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (5), 0, 2))); + view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (6), 0, 2))); } } @@ -511,7 +511,7 @@ std::string CmdCalendar::renderMonths ( // Loop through days in month and add to table. for (int d = 1; d <= daysInMonth[mpl]; ++d) { - Date temp (months[mpl], d, years[mpl]); + ISO8601d temp (months[mpl], d, years[mpl]); int dow = temp.dayOfWeek (); int woy = temp.weekOfYear (weekStart); diff --git a/src/commands/CmdHistory.cpp b/src/commands/CmdHistory.cpp index 335648c8d..dc81af131 100644 --- a/src/commands/CmdHistory.cpp +++ b/src/commands/CmdHistory.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include extern Context context; @@ -136,7 +137,7 @@ int CmdHistoryMonthly::execute (std::string& output) view.set (row, 0, y); priorYear = y; } - view.set (row, 1, Date::monthName(m)); + view.set (row, 1, ISO8601d::monthName(m)); int net = 0;