From 2a888aa881f19bdde1fa8480c932baf6230150d3 Mon Sep 17 00:00:00 2001 From: Suguru ARAKAWA Date: Tue, 13 Aug 2024 10:44:49 +0900 Subject: [PATCH] fix: support zone offset format without colon. --- src/takatori/datetime/parser/parser.yy | 8 +++++++- .../datetime/parser/datetime_parser_test.cpp | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/takatori/datetime/parser/parser.yy b/src/takatori/datetime/parser/parser.yy index 1041870..9c5583f 100644 --- a/src/takatori/datetime/parser/parser.yy +++ b/src/takatori/datetime/parser/parser.yy @@ -138,7 +138,13 @@ time offset : sign[s] INTEGER[h] { - $$ = offset_type { $s, $h, 0 }; + auto sign = $s; + auto field = $h; + if (field > 100) { + $$ = offset_type { sign, field / 100, field % 100 }; + } else { + $$ = offset_type { sign, field, 0 }; + } } | sign[s] INTEGER[h] ":" INTEGER[m] { diff --git a/test/takatori/datetime/parser/datetime_parser_test.cpp b/test/takatori/datetime/parser/datetime_parser_test.cpp index f4edca3..6c182c4 100644 --- a/test/takatori/datetime/parser/datetime_parser_test.cpp +++ b/test/takatori/datetime/parser/datetime_parser_test.cpp @@ -267,4 +267,18 @@ TEST_F(datetime_parser_test, offset_hour) { EXPECT_EQ(info.offset->minute, 0); } +TEST_F(datetime_parser_test, offset_without_colon) { + auto r = parse("+0102"); + ASSERT_TRUE(r.has_value()) << error(r); + auto&& info = r.value(); + + EXPECT_FALSE(info.date); + EXPECT_FALSE(info.time); + + ASSERT_TRUE(info.offset); + EXPECT_TRUE(info.offset->plus); + EXPECT_EQ(info.offset->hour, 1); + EXPECT_EQ(info.offset->minute, 2); +} + } // namespace takatori::datetime::parser