diff --git a/client-runtime/client-rt-core/common/src/software/aws/clientrt/time/Parsers.kt b/client-runtime/client-rt-core/common/src/software/aws/clientrt/time/Parsers.kt index 42d392eb7..3274d29db 100644 --- a/client-runtime/client-rt-core/common/src/software/aws/clientrt/time/Parsers.kt +++ b/client-runtime/client-rt-core/common/src/software/aws/clientrt/time/Parsers.kt @@ -215,7 +215,7 @@ private fun tzOffsetSecRfc5322(): Parser = { str, pos -> } // parse RFC-5322 timestamp -// HH:MM[:SS] GMT +// HH:MM[:SS][.(s*)] GMT private fun rfc5322Time(): Parser = { str, pos -> val (pos0, hour) = timeHour()(str, pos) val (pos1, min) = preceded(char(':'), timeMin())(str, pos0) @@ -225,8 +225,10 @@ private fun rfc5322Time(): Parser = { str, pos -> } else { ParseResult(pos1, 0) } - val (pos3, offsetSec) = preceded(::sp, tzOffsetSecRfc5322())(str, pos2) - ParseResult(pos3, ParsedTime(hour, min, sec, 0, offsetSec)) + + val (pos3, ns) = optionalOr(preceded(oneOf("."), timeNanos()), 0)(str, pos2) + val (pos4, offsetSec) = preceded(::sp, tzOffsetSecRfc5322())(str, pos3) + ParseResult(pos4, ParsedTime(hour, min, sec, ns, offsetSec)) } /** @@ -262,5 +264,5 @@ internal fun parseRfc5322(input: String): ParsedDatetime { val (_, ts) = preceded(::sp, rfc5322Time())(input, pos3) // Sun, 06 Nov 1994 08:49:37 GMT - return ParsedDatetime(year, month, day, ts.hour, ts.min, ts.sec, 0, ts.offsetSec) + return ParsedDatetime(year, month, day, ts.hour, ts.min, ts.sec, ts.ns, ts.offsetSec) } diff --git a/client-runtime/client-rt-core/common/test/software/aws/clientrt/time/ParseRfc5322Test.kt b/client-runtime/client-rt-core/common/test/software/aws/clientrt/time/ParseRfc5322Test.kt index af5e688a8..f82bbb049 100644 --- a/client-runtime/client-rt-core/common/test/software/aws/clientrt/time/ParseRfc5322Test.kt +++ b/client-runtime/client-rt-core/common/test/software/aws/clientrt/time/ParseRfc5322Test.kt @@ -33,7 +33,9 @@ class ParseRfc5322Test { // obsolete zone names ParseTest("Sun, 06 Nov 1994 08:49:37 UTC", 1994, 11, 6, 8, 49, 37, 0, 0), ParseTest("Sun, 06 Nov 1994 08:49:37 UT", 1994, 11, 6, 8, 49, 37, 0, 0), - ParseTest("Sun, 06 Nov 1994 08:49:37 Z", 1994, 11, 6, 8, 49, 37, 0, 0) + ParseTest("Sun, 06 Nov 1994 08:49:37 Z", 1994, 11, 6, 8, 49, 37, 0, 0), + // fractional seconds (required by awsJson1.1 apparently). See: https://github.com/awslabs/smithy/blob/master/smithy-aws-protocol-tests/model/awsJson1_1/kitchen-sink.smithy#L682 + ParseTest("Sun, 06 Nov 1994 08:49:37.001 GMT", 1994, 11, 6, 8, 49, 37, 1_000_000, 0) ) @Test