From 38355a2830a19705e466b3cc94acab702e344b97 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Fri, 20 Apr 2018 09:33:53 +0000 Subject: [PATCH] added: method Date::SerializeISO(Stream & out) outputs to the given stream: YYYY-MM-DDTHH:MM:SSZ, eg: 1990-02-12T13:05:39Z added: parsing date in a format: YYYY-MM-DDTHH:MM:SS ('T' letter given) git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1089 e52654a7-88a9-db11-a3e9-0013d4bc506e --- date/date.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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);