From 61fc32d04f765c637a72ad1b8267e5273674b30f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 30 Oct 2015 00:38:49 -0400 Subject: [PATCH] ISO8601: Added ::toISOLocalExtended method --- src/ISO8601.cpp | 22 ++++++++++++++++++++++ src/ISO8601.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/ISO8601.cpp b/src/ISO8601.cpp index 7685965e9..4b21eed52 100644 --- a/src/ISO8601.cpp +++ b/src/ISO8601.cpp @@ -1043,6 +1043,28 @@ std::string ISO8601d::toISO () const return iso.str (); } +//////////////////////////////////////////////////////////////////////////////// +// 1998-01-19T07:00:00 = YYYY-MM-DDThh:mm:ss +std::string ISO8601d::toISOLocalExtended () const +{ + struct tm* t = localtime (&_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; + + return iso.str (); +} + //////////////////////////////////////////////////////////////////////////////// double ISO8601d::toJulian () const { diff --git a/src/ISO8601.h b/src/ISO8601.h index 0a3fbd0f0..54642cbce 100644 --- a/src/ISO8601.h +++ b/src/ISO8601.h @@ -49,6 +49,7 @@ public: time_t toEpoch () const; std::string toEpochString () const; std::string toISO () const; + std::string toISOLocalExtended () const; double toJulian () const; void toMDY (int&, int&, int&) const; const std::string toString (const std::string& format = "m/d/Y") const;