[cpp-sp] branch main updated: Add a very primitive ISO timestamp parser.
Scott Cantor
cantor.2 at osu.edu
Tue Oct 21 15:44:06 UTC 2025
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository cpp-sp.
View the commit online:
http://git.shibboleth.net/view/?p=cpp-sp.git;a=commit;h=fbf6da34538a676cc9cf9dce39ff21d56d129aad
The following commit(s) were added to refs/heads/main by this push:
new fbf6da34 Add a very primitive ISO timestamp parser.
fbf6da34 is described below
commit fbf6da34538a676cc9cf9dce39ff21d56d129aad
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Oct 21 11:44:02 2025 -0400
Add a very primitive ISO timestamp parser.
---
shibsp/util/Misc.cpp | 15 ++++++++++++++-
tests/Makefile.am | 1 +
tests/util/ISOParserTests.cpp | 9 +++++++++
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/shibsp/util/Misc.cpp b/shibsp/util/Misc.cpp
index f49b2a04..f94eba2d 100644
--- a/shibsp/util/Misc.cpp
+++ b/shibsp/util/Misc.cpp
@@ -19,9 +19,12 @@
*/
#include "internal.h"
+#include "util/Date.h"
#include "util/Misc.h"
+#include <iomanip>
#include <set>
+#include <sstream>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
@@ -111,7 +114,17 @@ time_t shibsp::parseISODuration(const string& s)
time_t shibsp::parseISODateTime(const string& s)
{
- return 0;
+ if (s.empty() || s.back() != 'Z') {
+ return -1;
+ }
+
+ tm tmStruct = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, nullptr};
+ istringstream in(s);
+ in >> get_time(&tmStruct, "%Y-%m-%dT%T");
+ if (!in) {
+ return -1;
+ }
+ return timegm(&tmStruct);
}
bool FileSupport::exists(const char* path)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4fde6654..087c32d3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -22,6 +22,7 @@ shibsptest_SOURCES = \
remoting/impl/SecretSourceTests.cpp \
session/impl/MemorySessionCacheTests.cpp \
session/impl/FilesystemSessionCacheTests.cpp \
+ util/ISOParserTests.cpp \
util/PropertyTreeTests.cpp \
util/BoostPropertySetTests.cpp \
util/ReloadableXMLFileTests.cpp
diff --git a/tests/util/ISOParserTests.cpp b/tests/util/ISOParserTests.cpp
index a436d0d6..d41c8552 100644
--- a/tests/util/ISOParserTests.cpp
+++ b/tests/util/ISOParserTests.cpp
@@ -38,3 +38,12 @@ BOOST_AUTO_TEST_CASE(DurationTests)
BOOST_CHECK_EQUAL(parseISODuration("PT10H5M30S"), 10 * 60 * 60 + 5 * 60 + 30);
}
+
+BOOST_AUTO_TEST_CASE(TimestampTests)
+{
+ BOOST_CHECK_EQUAL(parseISODateTime("Foo"), -1);
+ BOOST_CHECK_EQUAL(parseISODateTime("2023-05-22T12:24:52"), -1);
+ BOOST_CHECK_EQUAL(parseISODateTime("2023-05-22T12:24:52Z"), 1684758292);
+ BOOST_CHECK_EQUAL(parseISODateTime("2025-10-21T14:11:35Z"), 1761055895);
+ BOOST_CHECK_EQUAL(parseISODateTime("2025-10-21 14:11:35Z"), -1);
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list