From 6d4c9331ddd0fe1093b6dfd105f0b8de0a209530 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Tue, 31 May 2016 19:37:17 -0400 Subject: [PATCH] Enable Time conversion to ISO8601 format --- include/openspace/util/time.h | 6 ++++++ src/util/time.cpp | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/openspace/util/time.h b/include/openspace/util/time.h index 992d2804e3..0dae7ac431 100644 --- a/include/openspace/util/time.h +++ b/include/openspace/util/time.h @@ -123,6 +123,12 @@ public: */ std::string currentTimeUTC() const; + /** + * Returns the current time as a ISO 8601 formatted, i.e YYYY-MM-DDThh:mm:ssZ + * \return The current time as a ISO 8601 formatted string + */ + std::string ISO8601() const; + /** * Sets the delta time value that is the number of seconds that should pass for each * real-time second. This value is used in the advanceTime(double) method to easily diff --git a/src/util/time.cpp b/src/util/time.cpp index a4aa96925f..a7cf79a806 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -99,6 +99,29 @@ std::string Time::currentTimeUTC() const { return SpiceManager::ref().dateFromEphemerisTime(_syncedTime); } +std::string Time::ISO8601() const { + std::string datetime = currentTimeUTC(); + std::string month = datetime.substr(5, 3); + + std::string MM = ""; + if (month == "JAN") MM = "01"; + else if (month == "FEB") MM = "02"; + else if (month == "MAR") MM = "03"; + else if (month == "APR") MM = "04"; + else if (month == "MAY") MM = "05"; + else if (month == "JUN") MM = "06"; + else if (month == "JUL") MM = "07"; + else if (month == "AUG") MM = "08"; + else if (month == "SEP") MM = "09"; + else if (month == "OCT") MM = "10"; + else if (month == "NOV") MM = "11"; + else if (month == "DEC") MM = "12"; + else ghoul_assert(false, "Bad month"); + + datetime.replace(4, 5, "-" + MM + "-"); + return datetime; +} + void Time::serialize(SyncBuffer* syncBuffer) { _syncMutex.lock();