added to Date: SerializeMonthAsRoman(Stream & out, int month) - serialize month in Roman numerals

added a param: 'bool roman_month' to some serialize methods
This commit is contained in:
Tomasz Sowa 2021-07-06 21:44:04 +02:00
parent 198945c97b
commit 1e5598cde1
1 changed files with 49 additions and 12 deletions

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2018, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -251,12 +251,21 @@ public:
int WeekDay() const;
/*
this method outputs to the given stream the number of a month in Roman numerals
e.g: if month is equal to 3 then III will be put to 'out'
month should be in the range [1,12]
*/
template<class Stream>
static void SerializeMonthAsRoman(Stream & out, int month);
/*
this method outputs to the given stream: YYYY-MM-DD, eg. 1990-02-12
ISO 8601 format
*/
template<class Stream>
void SerializeYearMonthDay(Stream & out) const;
void SerializeYearMonthDay(Stream & out, bool roman_month = false) const;
/*
@ -271,7 +280,7 @@ public:
this method outputs to the given stream: MM-DD, eg. 02-12 (02 month, 12 day)
*/
template<class Stream>
void SerializeMonthDay(Stream & out) const;
void SerializeMonthDay(Stream & out, bool roman_month = false) const;
/*
@ -286,7 +295,7 @@ public:
ISO 8601 format
*/
template<class Stream>
void Serialize(Stream & out) const;
void Serialize(Stream & out, bool roman_month = false, bool with_seconds = true) const;
/*
@ -547,13 +556,32 @@ void Date::SerializeInt(Stream & out, int val) const
}
template<class Stream>
void Date::SerializeMonthAsRoman(Stream & out, int month)
{
const char * month_roman[] = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII" };
if( month >= 1 && month <= 12 )
{
const char * month_str = month_roman[month - 1];
for( ; *month_str ; ++month_str)
out << *month_str;
}
}
template<class Stream>
void Date::SerializeYearMonthDay(Stream & out) const
void Date::SerializeYearMonthDay(Stream & out, bool roman_month) const
{
SerializeInt(out, year, 4);
out << '-';
SerializeInt(out, month);
if( roman_month )
SerializeMonthAsRoman(out, month);
else
SerializeInt(out, month);
out << '-';
SerializeInt(out, day);
}
@ -571,9 +599,13 @@ void Date::SerializeHourMinSec(Stream & out) const
template<class Stream>
void Date::SerializeMonthDay(Stream & out) const
void Date::SerializeMonthDay(Stream & out, bool roman_month) const
{
SerializeInt(out, month);
if( roman_month )
SerializeMonthAsRoman(out, month);
else
SerializeInt(out, month);
out << '-';
SerializeInt(out, day);
}
@ -589,17 +621,22 @@ void Date::SerializeHourMin(Stream & out) const
template<class Stream>
void Date::Serialize(Stream & out) const
void Date::Serialize(Stream & out, bool roman_month, bool with_seconds) const
{
SerializeYearMonthDay(out);
SerializeYearMonthDay(out, roman_month);
out << ' ';
SerializeHourMinSec(out);
if( with_seconds )
SerializeHourMinSec(out);
else
SerializeHourMin(out);
}
template<class Stream>
void Date::SerializeISO(Stream & out) const
{
SerializeYearMonthDay(out);
SerializeYearMonthDay(out, false);
out << 'T';
SerializeHourMinSec(out);
out << 'Z';