diff --git a/src/Date.cpp b/src/Date.cpp index 4644a1823..96d40ed65 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -44,13 +44,13 @@ static const char* relatives[] = { - "monday", - "tuesday", - "wednesday", - "thursday", - "friday", - "saturday", - "sunday", + STRING_DATE_SUNDAY_LONG, + STRING_DATE_MONDAY_LONG, + STRING_DATE_TUESDAY_LONG, + STRING_DATE_WEDNESDAY_LONG, + STRING_DATE_THURSDAY_LONG, + STRING_DATE_FRIDAY_LONG, + STRING_DATE_SATURDAY_LONG, "today", "tomorrow", "yesterday", @@ -377,23 +377,23 @@ std::string Date::monthName (int month) { static const char* months[12] = { - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December", + STRING_DATE_JANUARY_LONG, + STRING_DATE_FEBRUARY_LONG, + STRING_DATE_MARCH_LONG, + STRING_DATE_APRIL_LONG, + STRING_DATE_MAY_LONG, + STRING_DATE_JUNE_LONG, + STRING_DATE_JULY_LONG, + STRING_DATE_AUGUST_LONG, + STRING_DATE_SEPTEMBER_LONG, + STRING_DATE_OCTOBER_LONG, + STRING_DATE_NOEMBER_LONG, + STRING_DATE_DECEMBER_LONG, }; assert (month > 0); assert (month <= 12); - return months[month - 1]; + return ucFirst (months[month - 1]); } //////////////////////////////////////////////////////////////////////////////// @@ -401,16 +401,16 @@ void Date::dayName (int dow, std::string& name) { static const char* days[7] = { - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", + STRING_DATE_SUNDAY_LONG, + STRING_DATE_MONDAY_LONG, + STRING_DATE_TUESDAY_LONG, + STRING_DATE_WEDNESDAY_LONG, + STRING_DATE_THURSDAY_LONG, + STRING_DATE_FRIDAY_LONG, + STRING_DATE_SATURDAY_LONG, }; - name = days[dow]; + name = ucFirst (days[dow]); } //////////////////////////////////////////////////////////////////////////////// @@ -418,16 +418,16 @@ std::string Date::dayName (int dow) { static const char* days[7] = { - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", + STRING_DATE_SUNDAY_LONG, + STRING_DATE_MONDAY_LONG, + STRING_DATE_TUESDAY_LONG, + STRING_DATE_WEDNESDAY_LONG, + STRING_DATE_THURSDAY_LONG, + STRING_DATE_FRIDAY_LONG, + STRING_DATE_SATURDAY_LONG, }; - return days[dow]; + return ucFirst (days[dow]); } //////////////////////////////////////////////////////////////////////////////// @@ -463,13 +463,13 @@ int Date::dayOfWeek (const std::string& input) { std::string in = lowerCase (input); - if (in == "sunday" || in == "sun") return 0; - if (in == "monday" || in == "mon") return 1; - if (in == "tuesday" || in == "tue") return 2; - if (in == "wednesday" || in == "wed") return 3; - if (in == "thursday" || in == "thu") return 4; - if (in == "friday" || in == "fri") return 5; - if (in == "saturday" || in == "sat") return 6; + if (in == STRING_DATE_SUNDAY_LONG || in == STRING_DATE_SUNDAY_SHORT) return 0; + if (in == STRING_DATE_MONDAY_LONG || in == STRING_DATE_MONDAY_SHORT) return 1; + if (in == STRING_DATE_TUESDAY_LONG || in == STRING_DATE_TUESDAY_SHORT) return 2; + if (in == STRING_DATE_WEDNESDAY_LONG || in == STRING_DATE_WEDNESDAY_SHORT) return 3; + if (in == STRING_DATE_THURSDAY_LONG || in == STRING_DATE_THURSDAY_SHORT) return 4; + if (in == STRING_DATE_FRIDAY_LONG || in == STRING_DATE_FRIDAY_SHORT) return 5; + if (in == STRING_DATE_SATURDAY_LONG || in == STRING_DATE_SATURDAY_SHORT) return 6; return -1; } @@ -486,18 +486,18 @@ int Date::monthOfYear (const std::string& input) { std::string in = lowerCase (input); - if (in == "january" || in == "jan") return 1; - if (in == "february" || in == "feb") return 2; - if (in == "march" || in == "mar") return 3; - if (in == "april" || in == "apr") return 4; - if (in == "may" || in == "may") return 5; - if (in == "june" || in == "jun") return 6; - if (in == "july" || in == "jul") return 7; - if (in == "august" || in == "aug") return 8; - if (in == "september" || in == "sep") return 9; - if (in == "october" || in == "oct") return 10; - if (in == "november" || in == "nov") return 11; - if (in == "december" || in == "dec") return 12; + if (in == STRING_DATE_JANUARY_LONG || in == STRING_DATE_JANUARY_SHORT ) return 1; + if (in == STRING_DATE_FEBRUARY_LONG || in == STRING_DATE_FEBRUARY_SHORT ) return 2; + if (in == STRING_DATE_MARCH_LONG || in == STRING_DATE_MARCH_SHORT ) return 3; + if (in == STRING_DATE_APRIL_LONG || in == STRING_DATE_APRIL_SHORT ) return 4; + if (in == STRING_DATE_MAY_LONG || in == STRING_DATE_MAY_SHORT ) return 5; + if (in == STRING_DATE_JUNE_LONG || in == STRING_DATE_JUNE_SHORT ) return 6; + if (in == STRING_DATE_JULY_LONG || in == STRING_DATE_JULY_SHORT ) return 7; + if (in == STRING_DATE_AUGUST_LONG || in == STRING_DATE_AUGUST_SHORT ) return 8; + if (in == STRING_DATE_SEPTEMBER_LONG || in == STRING_DATE_SEPTEMBER_SHORT) return 9; + if (in == STRING_DATE_OCTOBER_LONG || in == STRING_DATE_OCTOBER_SHORT ) return 10; + if (in == STRING_DATE_NOEMBER_LONG || in == STRING_DATE_NOEMBER_SHORT ) return 11; + if (in == STRING_DATE_DECEMBER_LONG || in == STRING_DATE_DECEMBER_SHORT ) return 12; return -1; } diff --git a/src/commands/CmdCalendar.cpp b/src/commands/CmdCalendar.cpp index f8220a5a4..a666e5c99 100644 --- a/src/commands/CmdCalendar.cpp +++ b/src/commands/CmdCalendar.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -42,7 +43,7 @@ CmdCalendar::CmdCalendar () { _keyword = "calendar"; _usage = "task calendar [due|month year|year]"; - _description = "Shows a calendar, with due tasks marked."; + _description = STRING_CMD_CAL_USAGE; _read_only = true; _displays_id = true; } @@ -90,18 +91,8 @@ int CmdCalendar::execute (std::string& output) // Set up a vector of months, for autoComplete. std::vector monthNames; - monthNames.push_back ("january"); - monthNames.push_back ("february"); - monthNames.push_back ("march"); - monthNames.push_back ("april"); - monthNames.push_back ("may"); - monthNames.push_back ("june"); - monthNames.push_back ("july"); - monthNames.push_back ("august"); - monthNames.push_back ("september"); - monthNames.push_back ("october"); - monthNames.push_back ("november"); - monthNames.push_back ("december"); + for (int i = 1; i <= 12; ++i) + monthNames.push_back (lowerCase (Date::monthName (i))); // For autoComplete results. std::vector matches; @@ -137,7 +128,7 @@ int CmdCalendar::execute (std::string& output) { argMonth = strtol (arg->c_str (), NULL, 10); if (argMonth < 1 || argMonth > 12) - throw std::string ("Argument '") + *arg + "' is not a valid month."; + throw format (STRING_CMD_CAL_BAD_MONTH, *arg); } // "January" etc. @@ -145,11 +136,11 @@ int CmdCalendar::execute (std::string& output) { argMonth = Date::monthOfYear (matches[0]); if (argMonth == -1) - throw std::string ("Argument '") + *arg + "' is not a valid month."; + throw format (STRING_CMD_CAL_BAD_MONTH, *arg); } else - throw std::string ("Could not recognize argument '") + *arg + "'."; + throw format (STRING_CMD_CAL_BAD_ARG, *arg); } // Supported combinations: @@ -180,7 +171,7 @@ int CmdCalendar::execute (std::string& output) if (getpendingdate == true) { // Find the oldest pending due date. - Date oldest (12,31,2037); + Date oldest (12, 31, 2037); std::vector ::iterator task; for (task = tasks.begin (); task != tasks.end (); ++task) { @@ -364,8 +355,8 @@ int CmdCalendar::execute (std::string& output) ViewText holTable; holTable.width (context.getWidth ()); - holTable.add (Column::factory ("string", "Date")); - holTable.add (Column::factory ("string", "Holiday")); + holTable.add (Column::factory ("string", STRING_CMD_CAL_LABEL_DATE)); + holTable.add (Column::factory ("string", STRING_CMD_CAL_LABEL_HOL)); std::vector ::iterator it; for (it = holidays.begin (); it != holidays.end (); ++it) @@ -413,8 +404,7 @@ std::string CmdCalendar::renderMonths ( // What day of the week does the user consider the first? int weekStart = Date::dayOfWeek (context.config.get ("weekstart")); if (weekStart != 0 && weekStart != 1) - throw std::string ("The 'weekstart' configuration variable may " - "only contain 'Sunday' or 'Monday'."); + throw std::string (STRING_CMD_CAL_SUN_MON); // Build table for the number of months to be displayed. ViewText view; @@ -424,24 +414,24 @@ std::string CmdCalendar::renderMonths ( if (weekStart == 1) { view.add (Column::factory ("string.right", " ")); - view.add (Column::factory ("string.right", "Mo")); - view.add (Column::factory ("string.right", "Tu")); - view.add (Column::factory ("string.right", "We")); - view.add (Column::factory ("string.right", "Th")); - view.add (Column::factory ("string.right", "Fr")); - view.add (Column::factory ("string.right", "Sa")); - view.add (Column::factory ("string.right", "Su")); + view.add (Column::factory ("string.right", Date::dayName (1).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (2).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (3).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (4).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (5).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (6).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (0).substr (0, 2))); } else { view.add (Column::factory ("string.right", " ")); - view.add (Column::factory ("string.right", "Su")); - view.add (Column::factory ("string.right", "Mo")); - view.add (Column::factory ("string.right", "Tu")); - view.add (Column::factory ("string.right", "We")); - view.add (Column::factory ("string.right", "Th")); - view.add (Column::factory ("string.right", "Fr")); - view.add (Column::factory ("string.right", "Sa")); + view.add (Column::factory ("string.right", Date::dayName (0).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (1).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (2).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (3).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (4).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (5).substr (0, 2))); + view.add (Column::factory ("string.right", Date::dayName (6).substr (0, 2))); } } diff --git a/src/en-US.h b/src/en-US.h index b097cc5b4..7f42153f3 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -434,6 +434,12 @@ #define STRING_CMD_HELP_USAGE_LABEL "Usage:" #define STRING_CMD_HELP_USAGE_DESC "Runs rc.default.command, if specified." #define STRING_CMD_HELP_ALIASED "Aliased to '{1}'" +#define STRING_CMD_CAL_USAGE "Shows a calendar, with due tasks marked" +#define STRING_CMD_CAL_BAD_MONTH "Argument '{1}' is not a valid month." +#define STRING_CMD_CAL_BAD_ARG "Could not recognize argument '{1}'." +#define STRING_CMD_CAL_LABEL_DATE "Date" +#define STRING_CMD_CAL_LABEL_HOL "Holiday" +#define STRING_CMD_CAL_SUN_MON "The 'weekstart' configuration variable may only contain 'Sunday' or 'Monday'." // Config #define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake." @@ -458,6 +464,48 @@ #define STRING_DATE_INVALID_FORMAT "'{1}' is not a valid date in the '{2}' format." #define STRING_DATE_BAD_WEEKSTART "The 'weekstart' configuration variable may only contain 'Sunday' or 'Monday'." +#define STRING_DATE_JANUARY_LONG "january" +#define STRING_DATE_FEBRUARY_LONG "february" +#define STRING_DATE_MARCH_LONG "march" +#define STRING_DATE_APRIL_LONG "april" +#define STRING_DATE_MAY_LONG "may" +#define STRING_DATE_JUNE_LONG "june" +#define STRING_DATE_JULY_LONG "july" +#define STRING_DATE_AUGUST_LONG "august" +#define STRING_DATE_SEPTEMBER_LONG "september" +#define STRING_DATE_OCTOBER_LONG "october" +#define STRING_DATE_NOEMBER_LONG "november" +#define STRING_DATE_DECEMBER_LONG "december" + +#define STRING_DATE_JANUARY_SHORT "jan" +#define STRING_DATE_FEBRUARY_SHORT "feb" +#define STRING_DATE_MARCH_SHORT "mar" +#define STRING_DATE_APRIL_SHORT "apr" +#define STRING_DATE_MAY_SHORT "may" +#define STRING_DATE_JUNE_SHORT "jun" +#define STRING_DATE_JULY_SHORT "jul" +#define STRING_DATE_AUGUST_SHORT "aug" +#define STRING_DATE_SEPTEMBER_SHORT "sep" +#define STRING_DATE_OCTOBER_SHORT "oct" +#define STRING_DATE_NOEMBER_SHORT "nov" +#define STRING_DATE_DECEMBER_SHORT "dec" + +#define STRING_DATE_SUNDAY_LONG "sunday" +#define STRING_DATE_MONDAY_LONG "monday" +#define STRING_DATE_TUESDAY_LONG "tuesday" +#define STRING_DATE_WEDNESDAY_LONG "wednesday" +#define STRING_DATE_THURSDAY_LONG "thursday" +#define STRING_DATE_FRIDAY_LONG "friday" +#define STRING_DATE_SATURDAY_LONG "saturday" + +#define STRING_DATE_SUNDAY_SHORT "sun" +#define STRING_DATE_MONDAY_SHORT "mon" +#define STRING_DATE_TUESDAY_SHORT "tue" +#define STRING_DATE_WEDNESDAY_SHORT "wed" +#define STRING_DATE_THURSDAY_SHORT "thu" +#define STRING_DATE_FRIDAY_SHORT "fri" +#define STRING_DATE_SATURDAY_SHORT "sat" + // dependency #define STRING_DEPEND_BLOCKED "Task {1} is blocked by:" #define STRING_DEPEND_BLOCKING "and is blocking:"