Repository navigation
Description
Describe the bug
DateTime drops a numeric UTC offset when it parses a timestamp. For any offset other than zero, the date and time fields are passed to std::mktime, so they are read as the process's local time, and the offset value itself is never used. The result is off by the difference between the offset in the string and the local zone of the process.
This affects DateFormat::ISO_8601, ISO_8601_BASIC, RFC822 and AutoDetect, which share DateTime::ConvertTimestampStringToTimePoint. The parsers do keep the offset text (GetParsedTimezone()), but nothing reads it.
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
2019-12-16T22:48:18-01:00 and 2019-12-17T00:48:18+01:00 are the same instant as 2019-12-16T23:48:18Z (epoch 1576540098). This is what the Smithy DatetimeOffsets protocol tests expect, and the SDK already generates them under generated/protocol-tests/tests/output/*/tests/DatetimeOffsetsTest.cpp.
Current Behavior
With TZ=UTC:
2019-12-16T23:48:18Z -> 2019-12-16T23:48:18Z
2019-12-16T22:48:18-01:00 -> 2019-12-16T22:48:18Z (1 h early)
2019-12-17T00:48:18+01:00 -> 2019-12-17T00:48:18Z (1 h late)
2019-12-17T05:18:18+05:30 -> 2019-12-17T05:18:18Z (5.5 h late)
Tue, 17 Dec 2019 00:48:18 +0100 -> 2019-12-17T00:48:18Z (RFC822, 1 h late)
20191217T004818+0100 -> 2019-12-17T00:48:18Z (ISO 8601 basic, 1 h late)
The error log says Non-UTC timestamp detected. This is always a bug....
The result also depends on the machine's zone. With TZ=Europe/Berlin, the +01:00 string comes out right only because it happens to match the local zone. In the same zone -00:00 and +0000 come out an hour early, because the UTC check in the ISO 8601 parser only accepts Z and +00:00.
Reproduction Steps
#include <aws/core/Aws.h>
#include <aws/core/utils/DateTime.h>
#include <iostream>
int main() {
Aws::SDKOptions options;
Aws::InitAPI(options);
{
using namespace Aws::Utils;
DateTime z("2019-12-16T23:48:18Z", DateFormat::ISO_8601);
DateTime neg("2019-12-16T22:48:18-01:00", DateFormat::ISO_8601);
std::cout << z.Seconds() << " " << neg.Seconds() << std::endl; // 1576540098 1576536498 with TZ=UTC
}
Aws::ShutdownAPI(options);
}Possible Solution
In ConvertTimestampStringToTimePoint, when the parsed zone is a numeric offset (+hh, +hhmm or +hh:mm), use TimeGM and subtract the offset. Keep the existing mktime fallback for anything else. I have a small patch with a unit test and can open a PR.
Additional Information/Context
Where this shows up: response members parsed through the JSON or XML deserializers (DateTime(str, ISO_8601) / AutoDetect) when a service returns an offset, and credential Expiration values from credential_process or the container credentials endpoint (AWSCredentialsProvider.cpp, GeneralHTTPCredentialsProvider.cpp), which come from helper programs that may write a local offset. A wrong Expiration makes the SDK refresh credentials too early, or keep using them past their real expiry and get ExpiredToken errors.
I found this while reading the date parsers. I checked it with a small program that compiles DateTimeCommon.cpp from main (1d07b20) unchanged, run under TZ=UTC, Europe/Berlin and America/New_York. I did not build the full SDK or run the protocol test binaries.
AWS CPP SDK version used
main (1.11.935, 1d07b20)
Compiler and Version used
Apple clang 21.0.0
Operating System and version
macOS
Activity