aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvadim-xd <vadim-xd@yandex-team.com>2023-11-09 11:42:27 +0300
committervadim-xd <vadim-xd@yandex-team.com>2023-11-09 12:25:16 +0300
commit7695c63bbcdefb3b2dd6ca045d9a848c98154fc0 (patch)
tree2c77d1ffc38ba256adcf3e7f8ca901d4096427f9
parentc576fbcfb493c33a2342baeef87219b1839889c5 (diff)
downloadydb-7695c63bbcdefb3b2dd6ca045d9a848c98154fc0.tar.gz
Fix ISO 8601 parser for dates with year < 160
-rw-r--r--util/datetime/parser.rl617
-rw-r--r--util/datetime/parser_ut.cpp7
2 files changed, 16 insertions, 8 deletions
diff --git a/util/datetime/parser.rl6 b/util/datetime/parser.rl6
index 931f09eae1..5ea0baedc7 100644
--- a/util/datetime/parser.rl6
+++ b/util/datetime/parser.rl6
@@ -74,13 +74,14 @@ wkday = 'Mon'i | 'Tue'i | 'Wed'i | 'Thu'i | 'Fri'i | 'Sat'i | 'Sun'i;
weekday = 'Monday'i | 'Tuesday'i | 'Wednesday'i | 'Thursday'i
| 'Friday'i | 'Saturday'i | 'Sunday'i;
-action set_second { DateTimeFields.Second = I; }
-action set_minute { DateTimeFields.Minute = I; }
-action set_hour { DateTimeFields.Hour = I; }
-action set_day { DateTimeFields.Day = I; }
-action set_month { DateTimeFields.Month = I; }
-action set_year { DateTimeFields.SetLooseYear(I); }
-action set_zone_utc { DateTimeFields.ZoneOffsetMinutes = 0; }
+action set_second { DateTimeFields.Second = I; }
+action set_minute { DateTimeFields.Minute = I; }
+action set_hour { DateTimeFields.Hour = I; }
+action set_day { DateTimeFields.Day = I; }
+action set_month { DateTimeFields.Month = I; }
+action set_year { DateTimeFields.SetLooseYear(I); }
+action set_precise_year { DateTimeFields.Year = I; }
+action set_zone_utc { DateTimeFields.ZoneOffsetMinutes = 0; }
}%%
@@ -193,7 +194,7 @@ machine ISO8601DateTimeParser;
include DateTimeParserCommon;
-year = int4 @set_year;
+year = int4 @set_precise_year;
month = int2 @set_month;
day = int2 @set_day;
hour = int2 @set_hour;
diff --git a/util/datetime/parser_ut.cpp b/util/datetime/parser_ut.cpp
index 61364af997..6f5c300228 100644
--- a/util/datetime/parser_ut.cpp
+++ b/util/datetime/parser_ut.cpp
@@ -281,6 +281,13 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(637487058), p.GetResult(TInstant::Zero()));
}
+ Y_UNIT_TEST(TestIso8601BeforeEpoch) {
+ TIso8601DateTimeParser p;
+ static constexpr TStringBuf timestamp = "0001-01-01T00:00:00Z";
+ UNIT_ASSERT(p.ParsePart(timestamp.begin(), timestamp.size()));
+ UNIT_ASSERT_VALUES_EQUAL(p.GetDateTimeFields().Year, 1);
+ }
+
Y_UNIT_TEST(TestIso8601Correct) {
bool ret;
time_t t;