From 0c28d8dcbe6fb227f5cb59c75171e9525ac8efa7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 23 Nov 2020 19:36:07 +0100 Subject: [PATCH] time/ISO8601: support YYYY-MM (without day of month) --- src/time/ISO8601.cxx | 19 ++++++++++++++++++- src/time/ISO8601.hxx | 2 +- test/time/TestISO8601.cxx | 5 +++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/time/ISO8601.cxx b/src/time/ISO8601.cxx index 067e4c4ee..07ff3de81 100644 --- a/src/time/ISO8601.cxx +++ b/src/time/ISO8601.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2007-2019 Content Management AG + * Copyright 2007-2020 CM4all GmbH * All rights reserved. * * author: Max Kellermann @@ -32,6 +32,7 @@ #include "ISO8601.hxx" #include "Convert.hxx" +#include "Math.hxx" #include "util/StringBuffer.hxx" #include @@ -169,6 +170,13 @@ ParseTimeOfDay(const char *s, struct tm &tm, return end; } +static bool +StrptimeFull(const char *s, const char *fmt, struct tm *tm) noexcept +{ + const char *end = strptime(s, fmt, tm); + return end != nullptr && *end == 0; +} + #endif std::pair diff --git a/test/time/TestISO8601.cxx b/test/time/TestISO8601.cxx index cd0897c1a..f8a327ee3 100644 --- a/test/time/TestISO8601.cxx +++ b/test/time/TestISO8601.cxx @@ -46,6 +46,11 @@ static constexpr struct { { "2018-12-31T23:59:59Z", 1546300799, std::chrono::seconds(1) }, { "2019-01-01T00:00:00Z", 1546300800, std::chrono::seconds(1) }, + /* full month */ + { "1970-01", 0, std::chrono::hours(24 * 31) }, + { "2019-02", 1548979200, std::chrono::hours(24 * 28) }, + { "2019-01", 1546300800, std::chrono::hours(24 * 31) }, + /* only date */ { "1970-01-01", 0, std::chrono::hours(24) }, { "2019-02-04", 1549238400, std::chrono::hours(24) },