mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
ISO8601: Implemented ::dayNameShort and ::monthNameShort
- Added tests.
This commit is contained in:
parent
9143d8b8e7
commit
7a48d25eaa
3 changed files with 80 additions and 13 deletions
|
@ -1264,6 +1264,31 @@ std::string ISO8601d::monthName (int month)
|
|||
return Lexer::ucFirst (months[month - 1]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Static
|
||||
std::string ISO8601d::monthNameShort (int month)
|
||||
{
|
||||
static const char* months[12] =
|
||||
{
|
||||
STRING_DATE_JANUARY,
|
||||
STRING_DATE_FEBRUARY,
|
||||
STRING_DATE_MARCH,
|
||||
STRING_DATE_APRIL,
|
||||
STRING_DATE_MAY,
|
||||
STRING_DATE_JUNE,
|
||||
STRING_DATE_JULY,
|
||||
STRING_DATE_AUGUST,
|
||||
STRING_DATE_SEPTEMBER,
|
||||
STRING_DATE_OCTOBER,
|
||||
STRING_DATE_NOVEMBER,
|
||||
STRING_DATE_DECEMBER,
|
||||
};
|
||||
|
||||
assert (month > 0);
|
||||
assert (month <= 12);
|
||||
return Lexer::ucFirst (months[month - 1]).substr (0, 3);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Static
|
||||
std::string ISO8601d::dayName (int dow)
|
||||
|
@ -1282,6 +1307,24 @@ std::string ISO8601d::dayName (int dow)
|
|||
return Lexer::ucFirst (days[dow]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Static
|
||||
std::string ISO8601d::dayNameShort (int dow)
|
||||
{
|
||||
static const char* days[7] =
|
||||
{
|
||||
STRING_DATE_SUNDAY,
|
||||
STRING_DATE_MONDAY,
|
||||
STRING_DATE_TUESDAY,
|
||||
STRING_DATE_WEDNESDAY,
|
||||
STRING_DATE_THURSDAY,
|
||||
STRING_DATE_FRIDAY,
|
||||
STRING_DATE_SATURDAY,
|
||||
};
|
||||
|
||||
return Lexer::ucFirst (days[dow]).substr (0, 3);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Static
|
||||
int ISO8601d::dayOfWeek (const std::string& input)
|
||||
|
|
|
@ -67,7 +67,9 @@ public:
|
|||
static int daysInMonth (int, int);
|
||||
static int daysInYear (int);
|
||||
static std::string monthName (int);
|
||||
static std::string monthNameShort (int);
|
||||
static std::string dayName (int);
|
||||
static std::string dayNameShort (int);
|
||||
static int dayOfWeek (const std::string&);
|
||||
static int dayOfWeek (int, int, int);
|
||||
static int monthOfYear (const std::string&);
|
||||
|
|
|
@ -71,7 +71,7 @@ void testParse (
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int, char**)
|
||||
{
|
||||
UnitTest t (1006);
|
||||
UnitTest t (1025);
|
||||
|
||||
ISO8601d iso;
|
||||
std::string::size_type start = 0;
|
||||
|
@ -305,18 +305,32 @@ int main (int, char**)
|
|||
t.is (ISO8601d::daysInMonth (2, 2007), 28, "28 days in February 2007");
|
||||
|
||||
// Names.
|
||||
t.is (ISO8601d::monthName (1), "January", "1 = January");
|
||||
t.is (ISO8601d::monthName (2), "February", "2 = February");
|
||||
t.is (ISO8601d::monthName (3), "March", "3 = March");
|
||||
t.is (ISO8601d::monthName (4), "April", "4 = April");
|
||||
t.is (ISO8601d::monthName (5), "May", "5 = May");
|
||||
t.is (ISO8601d::monthName (6), "June", "6 = June");
|
||||
t.is (ISO8601d::monthName (7), "July", "7 = July");
|
||||
t.is (ISO8601d::monthName (8), "August", "8 = August");
|
||||
t.is (ISO8601d::monthName (9), "September", "9 = September");
|
||||
t.is (ISO8601d::monthName (10), "October", "10 = October");
|
||||
t.is (ISO8601d::monthName (11), "November", "11 = November");
|
||||
t.is (ISO8601d::monthName (12), "December", "12 = December");
|
||||
t.is (ISO8601d::monthName (1), "January", "1 = January");
|
||||
t.is (ISO8601d::monthName (2), "February", "2 = February");
|
||||
t.is (ISO8601d::monthName (3), "March", "3 = March");
|
||||
t.is (ISO8601d::monthName (4), "April", "4 = April");
|
||||
t.is (ISO8601d::monthName (5), "May", "5 = May");
|
||||
t.is (ISO8601d::monthName (6), "June", "6 = June");
|
||||
t.is (ISO8601d::monthName (7), "July", "7 = July");
|
||||
t.is (ISO8601d::monthName (8), "August", "8 = August");
|
||||
t.is (ISO8601d::monthName (9), "September", "9 = September");
|
||||
t.is (ISO8601d::monthName (10), "October", "10 = October");
|
||||
t.is (ISO8601d::monthName (11), "November", "11 = November");
|
||||
t.is (ISO8601d::monthName (12), "December", "12 = December");
|
||||
|
||||
// Names.
|
||||
t.is (ISO8601d::monthNameShort (1), "Jan", "1 = Jan");
|
||||
t.is (ISO8601d::monthNameShort (2), "Feb", "2 = Feb");
|
||||
t.is (ISO8601d::monthNameShort (3), "Mar", "3 = Mar");
|
||||
t.is (ISO8601d::monthNameShort (4), "Apr", "4 = Apr");
|
||||
t.is (ISO8601d::monthNameShort (5), "May", "5 = May");
|
||||
t.is (ISO8601d::monthNameShort (6), "Jun", "6 = Jun");
|
||||
t.is (ISO8601d::monthNameShort (7), "Jul", "7 = Jul");
|
||||
t.is (ISO8601d::monthNameShort (8), "Aug", "8 = Aug");
|
||||
t.is (ISO8601d::monthNameShort (9), "Sep", "9 = Sep");
|
||||
t.is (ISO8601d::monthNameShort (10), "Oct", "10 = Oct");
|
||||
t.is (ISO8601d::monthNameShort (11), "Nov", "11 = Nov");
|
||||
t.is (ISO8601d::monthNameShort (12), "Dec", "12 = Dec");
|
||||
|
||||
// Names.
|
||||
t.is (ISO8601d::monthOfYear ("January"), 1, "January = 1");
|
||||
|
@ -340,6 +354,14 @@ int main (int, char**)
|
|||
t.is (ISO8601d::dayName (5), "Friday", "5 == Friday");
|
||||
t.is (ISO8601d::dayName (6), "Saturday", "6 == Saturday");
|
||||
|
||||
t.is (ISO8601d::dayNameShort (0), "Sun", "0 == Sun");
|
||||
t.is (ISO8601d::dayNameShort (1), "Mon", "1 == Mon");
|
||||
t.is (ISO8601d::dayNameShort (2), "Tue", "2 == Tue");
|
||||
t.is (ISO8601d::dayNameShort (3), "Wed", "3 == Wed");
|
||||
t.is (ISO8601d::dayNameShort (4), "Thu", "4 == Thu");
|
||||
t.is (ISO8601d::dayNameShort (5), "Fri", "5 == Fri");
|
||||
t.is (ISO8601d::dayNameShort (6), "Sat", "6 == Sat");
|
||||
|
||||
t.is (ISO8601d::dayOfWeek ("SUNDAY"), 0, "SUNDAY == 0");
|
||||
t.is (ISO8601d::dayOfWeek ("sunday"), 0, "sunday == 0");
|
||||
t.is (ISO8601d::dayOfWeek ("Sunday"), 0, "Sunday == 0");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue