Repository navigation
Conversation
ConvertTimestampStringToTimePoint only used TimeGM for timestamps the parser recognised as UTC. A numeric offset such as +01:00 or -0500 fell through to std::mktime, which reads the fields as local time and never applies the offset, so the result depended on the process's zone. Read the parsed offset for ISO 8601, ISO 8601 basic and RFC 822 and subtract it from the TimeGM result. Anything that is not a numeric offset still takes the existing mktime path. See aws#4006.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available: #4006
Description of changes:
DateTime::ConvertTimestampStringToTimePointusesTimeGMonly when the parser decided the string is UTC. A numeric offset such as+01:00,+0530or-0500goes tostd::mktimeinstead. That reads the fields as the process's local time, and the offset itself is never applied. The result is wrong by the gap between the offset in the string and the local zone. In the ISO 8601 parser,-00:00and+0000also take that path, because the UTC check only acceptsZand+00:00.This change adds
DateParser::GetNumericUtcOffset(), which reads+hh,+hhmmor+hh:mm(and-) from the zone text the parsers already keep. When the zone is a numeric offset, the conversion usesTimeGM(&timeStruct) - offset. Anything else, such as a zone name or a partial offset like+01:0, still goes through the existingmktimepath with the same error log. ISO 8601, ISO 8601 basic, RFC 822 andAutoDetectall get this through the shared function.A changelog fragment is added with
tools/scripts/new-change.How I found it
I was reading the date parsers and noticed that
GetParsedTimezone()is filled in but nothing reads it. I then checked the generated SmithyDatetimeOffsetsprotocol tests undergenerated/protocol-tests/tests/output/*/tests/DatetimeOffsetsTest.cpp. They expect2019-12-16T22:48:18-01:00and2019-12-17T00:48:18+01:00to be epoch 1576540098, which the current code returns only when the offset happens to match the local zone.Where this can show up in practice
DateTime(str, ISO_8601)/AutoDetect) when a service or endpoint sends a timestamp with a non-zero offset.Expirationfromcredential_processand the container credentials endpoint (AWSCredentialsProvider.cpp,GeneralHTTPCredentialsProvider.cpp). These come from helper programs, which may write a local offset. A wrong expiry makes the SDK refresh too early, or keep credentials past their real expiry and getExpiredToken.In both cases the result also changes with the machine's
TZ, so the same input can behave differently on two hosts.Validation
I added
DateTimeTest.TestParsingWithNonZeroUtcOffset. It compares 10 offset forms against2019-12-16T23:48:18Z: ISO 8601 with-01:00,+01:00,+05:30,-00:00,+0000and.000-10:00; ISO 8601 basic with+0100; RFC 822 with+0100and-0500; andAutoDetectwith+01:00.I could not build the full SDK here. Instead, I compiled
DateTimeCommon.cppandplatform/linux-shared/Time.cppon their own against the core headers, with a small driver that runs the same 14 strings (the 10 above plus UTC controls). I ran it once with the source from main and once with this change, under three zones:The controls (
Z,+00:00, RFC 822GMT, ISO 8601 basicZ) are correct in both builds.+01:0is still parsed through the old fallback as before. The changed lines passclang-format-diff.pywith the repo's.clang-format.Not run: the full SDK build, the gtest binary for
aws-cpp-sdk-core-tests, the protocol test binaries, clang-tidy, and anything on Windows. The WindowsTimeGMwas not exercised.Check all that applies:
Aws::Time::TimeGM, which the UTC path already uses on every platform. It removes a dependency on the local zone.Check which platforms you have built SDK on to verify the correctness of this PR.
I did not build the SDK on any platform. The standalone check above ran on macOS.
AI disclosure: I used an AI coding agent to read the parsers, draft the patch and test, and run the standalone check. I (Dezhen Lu) reviewed the change and the results.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.