ISO8601d: Conversion from Date to ISO8601d

This commit is contained in:
Paul Beckingham 2015-09-26 23:08:29 -04:00
parent f32e53c7d6
commit 68c6afbdd4
4 changed files with 29 additions and 29 deletions

View file

@ -32,6 +32,7 @@
#include <Lexer.h> #include <Lexer.h>
#include <Nibbler.h> #include <Nibbler.h>
#ifdef NIBBLER_FEATURE_DATE #ifdef NIBBLER_FEATURE_DATE
#include <ISO8601.h>
#include <Date.h> #include <Date.h>
#endif #endif
#ifdef NIBBLER_FEATURE_REGEX #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 + 1]) &&
! Lexer::isDigit ((*_input)[i + 2])) ! Lexer::isDigit ((*_input)[i + 2]))
{ {
wday = Date::dayOfWeek (_input->substr (i, 3).c_str ()); wday = ISO8601d::dayOfWeek (_input->substr (i, 3).c_str ());
i += (format[f] == 'a') ? 3 : Date::dayName (wday).size (); i += (format[f] == 'a') ? 3 : ISO8601d::dayName (wday).size ();
} }
else else
return false; return false;
@ -834,8 +835,8 @@ bool Nibbler::getDate (const std::string& format, time_t& t)
{ {
if (month != -1) if (month != -1)
return false; return false;
month = Date::monthOfYear (_input->substr (i, 3).c_str()); month = ISO8601d::monthOfYear (_input->substr (i, 3).c_str());
i += (format[f] == 'b') ? 3 : Date::monthName (month).size (); i += (format[f] == 'b') ? 3 : ISO8601d::monthName (month).size ();
} }
else else
return false; return false;

View file

@ -27,7 +27,6 @@
#include <cmake.h> #include <cmake.h>
#include <Context.h> #include <Context.h>
#include <ISO8601.h> #include <ISO8601.h>
#include <Date.h>
#include <ColUDA.h> #include <ColUDA.h>
#include <text.h> #include <text.h>
#include <utf8.h> #include <utf8.h>
@ -89,14 +88,14 @@ void ColumnUDA::measure (Task& task, unsigned int& minimum, unsigned int& maximu
// rc.report.<report>.dateformat // rc.report.<report>.dateformat
// rc.dateformat.report // rc.dateformat.report
// rc.dateformat // 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"); std::string format = context.config.get ("report." + _report + ".dateformat");
if (format == "") if (format == "")
format = context.config.get ("dateformat.report"); format = context.config.get ("dateformat.report");
if (format == "") if (format == "")
format = context.config.get ("dateformat"); format = context.config.get ("dateformat");
minimum = maximum = Date::length (format); minimum = maximum = ISO8601d::length (format);
} }
else if (_type == "duration") else if (_type == "duration")
{ {
@ -153,8 +152,7 @@ void ColumnUDA::render (
lines.push_back ( lines.push_back (
color.colorize ( color.colorize (
leftJustify ( leftJustify (
Date ((time_t) strtol (value.c_str (), NULL, 10)) ISO8601d ((time_t) strtol (value.c_str (), NULL, 10)).toString (format), width)));
.toString (format), width)));
} }
else if (_type == "duration") else if (_type == "duration")
{ {

View file

@ -99,7 +99,7 @@ int CmdCalendar::execute (std::string& output)
// Set up a vector of months, for autoComplete. // Set up a vector of months, for autoComplete.
std::vector <std::string> monthNames; std::vector <std::string> monthNames;
for (int i = 1; i <= 12; ++i) for (int i = 1; i <= 12; ++i)
monthNames.push_back (lowerCase (Date::monthName (i))); monthNames.push_back (lowerCase (ISO8601d::monthName (i)));
// For autoComplete results. // For autoComplete results.
std::vector <std::string> matches; std::vector <std::string> matches;
@ -140,7 +140,7 @@ int CmdCalendar::execute (std::string& output)
// "January" etc. // "January" etc.
else if (autoComplete (lowerCase (arg), monthNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1) 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) if (argMonth == -1)
throw format (STRING_CMD_CAL_BAD_MONTH, arg); 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) // Print month headers (cheating on the width settings, yes)
for (int i = 0 ; i < monthsPerLine ; i++) for (int i = 0 ; i < monthsPerLine ; i++)
{ {
std::string month = Date::monthName (nextM); std::string month = ISO8601d::monthName (nextM);
// 12345678901234567890123456 = 26 chars wide // 12345678901234567890123456 = 26 chars wide
// ^^ = center // ^^ = center
@ -426,7 +426,7 @@ std::string CmdCalendar::renderMonths (
int monthsPerLine) int monthsPerLine)
{ {
// What day of the week does the user consider the first? // 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) if (weekStart != 0 && weekStart != 1)
throw std::string (STRING_CMD_CAL_SUN_MON); throw std::string (STRING_CMD_CAL_SUN_MON);
@ -441,24 +441,24 @@ std::string CmdCalendar::renderMonths (
if (weekStart == 1) if (weekStart == 1)
{ {
view.add (Column::factory ("string.right", " ")); 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 (ISO8601d::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 (ISO8601d::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 (ISO8601d::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 (ISO8601d::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 (ISO8601d::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 (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 (0), 0, 2)));
} }
else else
{ {
view.add (Column::factory ("string.right", " ")); 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 (ISO8601d::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 (ISO8601d::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 (ISO8601d::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 (ISO8601d::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 (ISO8601d::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 (ISO8601d::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 (6), 0, 2)));
} }
} }
@ -511,7 +511,7 @@ std::string CmdCalendar::renderMonths (
// Loop through days in month and add to table. // Loop through days in month and add to table.
for (int d = 1; d <= daysInMonth[mpl]; ++d) 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 dow = temp.dayOfWeek ();
int woy = temp.weekOfYear (weekStart); int woy = temp.weekOfYear (weekStart);

View file

@ -32,6 +32,7 @@
#include <main.h> #include <main.h>
#include <text.h> #include <text.h>
#include <i18n.h> #include <i18n.h>
#include <ISO8601.h>
#include <CmdHistory.h> #include <CmdHistory.h>
extern Context context; extern Context context;
@ -136,7 +137,7 @@ int CmdHistoryMonthly::execute (std::string& output)
view.set (row, 0, y); view.set (row, 0, y);
priorYear = y; priorYear = y;
} }
view.set (row, 1, Date::monthName(m)); view.set (row, 1, ISO8601d::monthName(m));
int net = 0; int net = 0;