diff options
author | den <den@yandex-team.ru> | 2022-02-10 16:49:43 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:43 +0300 |
commit | 0beaf5069375bfa9589dbf4c281fbfcc7b11f71d (patch) | |
tree | 2a9075fe9636ba84e8db3369d5d39589cccac932 /util/datetime | |
parent | 64b907678a38848c4af3d0270ccee688c5d7752c (diff) | |
download | ydb-0beaf5069375bfa9589dbf4c281fbfcc7b11f71d.tar.gz |
Restoring authorship annotation for <den@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/datetime')
-rw-r--r-- | util/datetime/parser.rl6 | 110 | ||||
-rw-r--r-- | util/datetime/parser_ut.cpp | 22 |
2 files changed, 66 insertions, 66 deletions
diff --git a/util/datetime/parser.rl6 b/util/datetime/parser.rl6 index 931f09eae1..d2df0a674b 100644 --- a/util/datetime/parser.rl6 +++ b/util/datetime/parser.rl6 @@ -4,55 +4,55 @@ #include <cctype> #include <ctime> #include <numeric> - + #include <util/datetime/parser.h> #include <util/generic/ymath.h> - + %%{ - + machine DateTimeParserCommon; - + sp = ' '; -action clear_int { +action clear_int { I = 0; Dc = 0; -} - -action update_int { +} + +action update_int { I = I * 10 + (fc - '0'); ++Dc; -} - +} + int = (digit+) >clear_int $update_int; - -int1 = digit - >clear_int - $update_int; - -int2 = (digit digit) + +int1 = digit >clear_int - $update_int; + $update_int; +int2 = (digit digit) + >clear_int + $update_int; + int3 = (digit digit digit) >clear_int $update_int; -int4 = (digit digit digit digit) - >clear_int - $update_int; - -int12 = (digit digit?) - >clear_int - $update_int; +int4 = (digit digit digit digit) + >clear_int + $update_int; + +int12 = (digit digit?) + >clear_int + $update_int; int24 = ( digit digit ( digit digit )? ) - >clear_int - $update_int; - + >clear_int + $update_int; + # According to both RFC2822 and RFC2616 dates MUST be case-sensitive, # but Andrey fomichev@ wants relaxed parser @@ -97,7 +97,7 @@ ws0 = (space*); dow_spec = ( wkday ',' )?; day = int12 %set_day; -year = int24 %set_year; +year = int24 %set_year; # actually it must be from 0 to 23 hour = int2 %set_hour; @@ -107,39 +107,39 @@ min = int2 %set_minute; # actually it must be from 0 to 59 sec = int2 %set_second; - + sec_spec = ( ':' . sec )?; -# so called "military zone offset". I hardly believe someone uses it now, but we MUST respect RFc822 -action set_mil_offset { +# so called "military zone offset". I hardly believe someone uses it now, but we MUST respect RFc822 +action set_mil_offset { char c = (char)toupper(fc); - if (c == 'Z') + if (c == 'Z') DateTimeFields.ZoneOffsetMinutes = 0; - else { - if (c <= 'M') { - // ['A'..'M'] \ 'J' - if (c < 'J') + else { + if (c <= 'M') { + // ['A'..'M'] \ 'J' + if (c < 'J') DateTimeFields.ZoneOffsetMinutes = (i32)TDuration::Hours(c - 'A' + 1).Minutes(); - else + else DateTimeFields.ZoneOffsetMinutes = (i32)TDuration::Hours(c - 'A').Minutes(); - } else { - // ['N'..'Y'] + } else { + // ['N'..'Y'] DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(c - 'N' + 1).Minutes(); - } - } -} - -action set_digit_offset { + } + } +} + +action set_digit_offset { DateTimeFields.ZoneOffsetMinutes = Sign * (i32)(TDuration::Hours(I / 100) + TDuration::Minutes(I % 100)).Minutes(); -} - -mil_zone = /[A-IK-Za-ik-z]/ $set_mil_offset; - +} + +mil_zone = /[A-IK-Za-ik-z]/ $set_mil_offset; + # actions % were replaced with @ (when the script was migrated to ragel 5.24) # because ragel 5.24 does not call to the % action if it be called at the very end of string. # it is a bug in ragel 5 because ragel 6.2 works correctly with % at the end of string. # see http://www.complang.org/ragel/ChangeLog. - + zone = 'UT' @{ DateTimeFields.ZoneOffsetMinutes = 0; } | 'GMT' @{ DateTimeFields.ZoneOffsetMinutes = 0; } | 'EST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(5).Minutes();} @@ -156,11 +156,11 @@ digit_offset = ('+' | '-') > { Sign = fc == '+' ? 1 : -1; } . int4 @set_digit_of offset = ( zone | mil_zone | digit_offset ); rfc822datetime = ws0 . dow_spec . ws0 . day . ws1 . month3 . ws1 . year . ws1 . hour . ':' . min . sec_spec . ws1 . offset . ws0; - + main := rfc822datetime; - + write data noerror; - + }%% TRfc822DateTimeParserDeprecated::TRfc822DateTimeParserDeprecated() { @@ -680,7 +680,7 @@ bool ParseRFC822DateTime(const char* input, size_t inputLen, time_t& utcTime) { utcTime = ParseUnsafe<TRfc822DateTimeParser, TInstant>(input, inputLen).TimeT(); return true; } catch (const TDateTimeParseException&) { - return false; + return false; } } @@ -690,8 +690,8 @@ bool ParseISO8601DateTime(const char* input, size_t inputLen, time_t& utcTime) { return true; } catch (const TDateTimeParseException&) { return false; - } -} + } +} bool ParseHTTPDateTime(const char* input, size_t inputLen, time_t& utcTime) { try { diff --git a/util/datetime/parser_ut.cpp b/util/datetime/parser_ut.cpp index 61364af997..6cea48cad0 100644 --- a/util/datetime/parser_ut.cpp +++ b/util/datetime/parser_ut.cpp @@ -1,7 +1,7 @@ #include "parser.h" #include <library/cpp/testing/unittest/registar.h> - + static const time_t SECONDS_PER_HOUR = 3600; static const time_t SECONDS_PER_MINUTE = 60; @@ -68,7 +68,7 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) { r = ParseRFC822DateTime("Fri, 4 Mar 2005 19:34:45 +0300", t); UNIT_ASSERT(r); UNIT_ASSERT_EQUAL(t, (time_t)1109954085); - + r = ParseRFC822DateTime("Fri, 4 Mar 05 19:34:45 +0300", t); UNIT_ASSERT(r); UNIT_ASSERT_EQUAL(t, (time_t)1109954085); @@ -126,8 +126,8 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) { r = ParseRFC822DateTime("Sat, 14 Feb 2009 02:31:30 +0300", t); // spaces with tabs UNIT_ASSERT(r); UNIT_ASSERT_EQUAL(t, (time_t)1234567890); - } - + } + time_t GetOffset(char militaryZone) { char ch = (char)toupper(militaryZone); if (ch == 'Z') { @@ -184,15 +184,15 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) { r = ParseRFC822DateTime("Fri, 4 Mar 2005 19:34:45 UTC", t); UNIT_ASSERT(!r); UNIT_ASSERT_EQUAL(t, (time_t)54321); - - // TODO: check semantic validity of parsed date (30 Feb, 88:90 etc.). - // The following tests MUST fail (they don't now) + + // TODO: check semantic validity of parsed date (30 Feb, 88:90 etc.). + // The following tests MUST fail (they don't now) // r = ParseRFC822DateTime("45 Mar 2005 19:34:45 UT", t); // UNIT_ASSERT_EQUAL(r, false); - + // r = ParseRFC822DateTime("29 Feb 2005 19:34:45 +0300", t); // UNIT_ASSERT_EQUAL(r, false); - + // r = ParseRFC822DateTime("31 Apr 2004 19:34:45 +0300", t); // UNIT_ASSERT_EQUAL(r, false); @@ -253,7 +253,7 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) { UNIT_ASSERT(!r); r = ParseRFC822DateTime("Mon, 17 Nov 2008 19:34:45 -03030", t); UNIT_ASSERT(!r); - } + } Y_UNIT_TEST(TestRfc822Partial) { TRfc822DateTimeParser p; @@ -267,7 +267,7 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) { UNIT_ASSERT(p.ParsePart(part3, strlen(part3))); UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(1109954086), p.GetResult(TInstant::Zero())); } - + Y_UNIT_TEST(TestIso8601Partial) { TIso8601DateTimeParser p; const char* part1 = "1990-03-15T15:1"; |