Skip to content

Commit

Permalink
fix: support zone offset format without colon.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashigeru committed Aug 13, 2024
1 parent 922e37d commit 2a888aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/takatori/datetime/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -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]
{
Expand Down
14 changes: 14 additions & 0 deletions test/takatori/datetime/parser/datetime_parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2a888aa

Please sign in to comment.