diff --git a/date/date.h b/date/date.h index 487f921..f6a47b3 100644 --- a/date/date.h +++ b/date/date.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2012, Tomasz Sowa + * Copyright (c) 2012-2018, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -288,6 +288,14 @@ public: void Serialize(Stream & out) const; + /* + this method outputs to the given stream: YYYY-MM-DDTHH:MM:SSZ, eg: 1990-02-12T13:05:39Z + ISO 8601 format + */ + template + void SerializeISO(Stream & out) const; + + /* parsing day month and year the input string can be as follows: @@ -567,6 +575,14 @@ void Date::Serialize(Stream & out) const SerializeHourMinSec(out); } +template +void Date::SerializeISO(Stream & out) const +{ + SerializeYearMonthDay(out); + out << 'T'; + SerializeHourMinSec(out); + out << 'Z'; +} template @@ -771,8 +787,20 @@ const CStringType * after; bool result = false; if( ParseYearMonthDay(str, &after) ) + { + SkipWhite(after); + + if( *after == 'T' ) + { + // ISO 8601 format + // https://en.wikipedia.org/wiki/ISO_8601 + // at the moment skip the 'T' character only + after += 1; + } + if( ParseHourMinSec(after, &after) ) result = true; + } SetAfter(after, str_after);