From 2414f6b3d4f655f765d3831679bc9bfe21f9fc84 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 26 Sep 2015 18:42:32 -0400 Subject: [PATCH] ISO8601d: Added ::toISO --- src/ISO8601.cpp | 20 ++++++++++++++++++++ src/ISO8601.h | 1 + 2 files changed, 21 insertions(+) diff --git a/src/ISO8601.cpp b/src/ISO8601.cpp index fb1332f56..1f2765f38 100644 --- a/src/ISO8601.cpp +++ b/src/ISO8601.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -854,6 +855,25 @@ std::string ISO8601d::toEpochString () return epoch.str (); } +//////////////////////////////////////////////////////////////////////////////// +// 19980119T070000Z = YYYYMMDDThhmmssZ +std::string ISO8601d::toISO () +{ + struct tm* t = gmtime (&_date); + + std::stringstream iso; + iso << std::setw (4) << std::setfill ('0') << t->tm_year + 1900 + << std::setw (2) << std::setfill ('0') << t->tm_mon + 1 + << std::setw (2) << std::setfill ('0') << t->tm_mday + << "T" + << std::setw (2) << std::setfill ('0') << t->tm_hour + << std::setw (2) << std::setfill ('0') << t->tm_min + << std::setw (2) << std::setfill ('0') << t->tm_sec + << "Z"; + + return iso.str (); +} + //////////////////////////////////////////////////////////////////////////////// double ISO8601d::toJulian () { diff --git a/src/ISO8601.h b/src/ISO8601.h index 87730df8c..cf4824f23 100644 --- a/src/ISO8601.h +++ b/src/ISO8601.h @@ -48,6 +48,7 @@ public: time_t toEpoch (); std::string toEpochString (); + std::string toISO (); double toJulian (); void toMDY (int&, int&, int&);