Add DateTime::toIsoStringWithCustomDelimiters()
This commit is contained in:
parent
9fe7053869
commit
4b67736adf
|
@ -112,8 +112,8 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
|
||||||
set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parser, IO and conversion utilities")
|
set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parser, IO and conversion utilities")
|
||||||
set(META_FEATURES_FOR_COMPILER_DETECTION_HEADER cxx_thread_local)
|
set(META_FEATURES_FOR_COMPILER_DETECTION_HEADER cxx_thread_local)
|
||||||
set(META_VERSION_MAJOR 5)
|
set(META_VERSION_MAJOR 5)
|
||||||
set(META_VERSION_MINOR 3)
|
set(META_VERSION_MINOR 4)
|
||||||
set(META_VERSION_PATCH 1)
|
set(META_VERSION_PATCH 0)
|
||||||
|
|
||||||
# find required 3rd party libraries
|
# find required 3rd party libraries
|
||||||
include(3rdParty)
|
include(3rdParty)
|
||||||
|
|
|
@ -210,14 +210,14 @@ void DateTime::toString(string &result, DateTimeOutputFormat format, bool noMill
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns the string representation of the current instance in the ISO format,
|
* \brief Returns the string representation of the current instance in the ISO format with custom delimiters,
|
||||||
* eg. 2016-08-29T21:32:31.588539814+02:00.
|
* eg. 2016/08/29T21-32-31.588539814+02:00 with '/' as \a dateDelimiter and '-' as \a timeDelimiter.
|
||||||
*/
|
*/
|
||||||
string DateTime::toIsoString(TimeSpan timeZoneDelta) const
|
string DateTime::toIsoStringWithCustomDelimiters(TimeSpan timeZoneDelta, char dateDelimiter, char timeDelimiter, char timeZoneDelimiter) const
|
||||||
{
|
{
|
||||||
stringstream s(stringstream::in | stringstream::out);
|
stringstream s(stringstream::in | stringstream::out);
|
||||||
s << setfill('0');
|
s << setfill('0');
|
||||||
s << setw(4) << year() << '-' << setw(2) << month() << '-' << setw(2) << day() << 'T' << setw(2) << hour() << ':' << setw(2) << minute() << ':'
|
s << setw(4) << year() << dateDelimiter << setw(2) << month() << dateDelimiter << setw(2) << day() << 'T' << setw(2) << hour() << timeDelimiter << setw(2) << minute() << timeDelimiter
|
||||||
<< setw(2) << second();
|
<< setw(2) << second();
|
||||||
const int milli(millisecond());
|
const int milli(millisecond());
|
||||||
const int micro(microsecond());
|
const int micro(microsecond());
|
||||||
|
@ -238,11 +238,20 @@ string DateTime::toIsoString(TimeSpan timeZoneDelta) const
|
||||||
} else {
|
} else {
|
||||||
s << '+';
|
s << '+';
|
||||||
}
|
}
|
||||||
s << setw(2) << timeZoneDelta.hours() << ':' << setw(2) << timeZoneDelta.minutes();
|
s << setw(2) << timeZoneDelta.hours() << timeZoneDelimiter << setw(2) << timeZoneDelta.minutes();
|
||||||
}
|
}
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Returns the string representation of the current instance in the ISO format,
|
||||||
|
* eg. 2016-08-29T21:32:31.588539814+02:00.
|
||||||
|
*/
|
||||||
|
string DateTime::toIsoString(TimeSpan timeZoneDelta) const
|
||||||
|
{
|
||||||
|
return toIsoStringWithCustomDelimiters(timeZoneDelta);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns the string representation as C-style string for the given day of week.
|
* \brief Returns the string representation as C-style string for the given day of week.
|
||||||
*
|
*
|
||||||
|
|
|
@ -85,6 +85,7 @@ public:
|
||||||
constexpr bool isSameDay(const DateTime &other) const;
|
constexpr bool isSameDay(const DateTime &other) const;
|
||||||
std::string toString(DateTimeOutputFormat format = DateTimeOutputFormat::DateAndTime, bool noMilliseconds = false) const;
|
std::string toString(DateTimeOutputFormat format = DateTimeOutputFormat::DateAndTime, bool noMilliseconds = false) const;
|
||||||
void toString(std::string &result, DateTimeOutputFormat format = DateTimeOutputFormat::DateAndTime, bool noMilliseconds = false) const;
|
void toString(std::string &result, DateTimeOutputFormat format = DateTimeOutputFormat::DateAndTime, bool noMilliseconds = false) const;
|
||||||
|
std::string toIsoStringWithCustomDelimiters(TimeSpan timeZoneDelta = TimeSpan(), char dateDelimiter = '-', char timeDelimiter = ':', char timeZoneDelimiter = ':') const;
|
||||||
std::string toIsoString(TimeSpan timeZoneDelta = TimeSpan()) const;
|
std::string toIsoString(TimeSpan timeZoneDelta = TimeSpan()) const;
|
||||||
constexpr std::time_t toTimeStamp() const;
|
constexpr std::time_t toTimeStamp() const;
|
||||||
static const char *printDayOfWeek(DayOfWeek dayOfWeek, bool abbreviation = false);
|
static const char *printDayOfWeek(DayOfWeek dayOfWeek, bool abbreviation = false);
|
||||||
|
|
Loading…
Reference in New Issue