Skip to content

Commit

Permalink
Add tests that call out how Timestamp handles negative nanos.
Browse files Browse the repository at this point in the history
Duration already has a care or two where there are just nanos, but Timestamp doesn't
and the handing of negative values in Timestamp can be a little strange, so this
should probably get a conformance test.

PiperOrigin-RevId: 716668059
  • Loading branch information
thomasvl authored and copybara-github committed Jan 17, 2025
1 parent d02df7f commit 3423d7c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions conformance/binary_json_conformance_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3093,6 +3093,27 @@ void BinaryAndJsonConformanceSuiteImpl<
})",
"repeated_timestamp: {seconds: -62135596800}"
"repeated_timestamp: {seconds: 253402300799 nanos: 999999999}");
RunValidJsonTest("TimestampEpochValue", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T00:00:00.000Z"})",
"optional_timestamp: {seconds: 0}");
RunValidJsonTest("TimestampNanoAfterEpochlValue", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T00:00:00.000000001Z"})",
"optional_timestamp: {seconds: 0 nanos: 1}");
RunValidJsonTest("TimestampNanoBeforeEpochValue", REQUIRED,
R"({"optionalTimestamp": "1969-12-31T23:59:59.999999999Z"})",
"optional_timestamp: {seconds: -1 nanos: 999999999}");
RunValidJsonTest("TimestampLittleAfterEpochlValue", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T00:00:01.000000001Z"})",
"optional_timestamp: {seconds: 1 nanos: 1}");
RunValidJsonTest("TimestampLittleBeforeEpochValue", REQUIRED,
R"({"optionalTimestamp": "1969-12-31T23:59:58.999999999Z"})",
"optional_timestamp: {seconds: -2 nanos: 999999999}");
RunValidJsonTest("TimestampTenAndHalfSecondsAfterEpochValue", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T00:00:10.500Z"})",
"optional_timestamp: {seconds: 10 nanos: 500000000}");
RunValidJsonTest("TimestampTenAndHalfSecondsBeforeEpochValue", REQUIRED,
R"({"optionalTimestamp": "1969-12-31T23:59:49.500Z"})",
"optional_timestamp: {seconds: -11 nanos: 500000000}");
RunValidJsonTest("TimestampLeap", REQUIRED,
R"({"optionalTimestamp": "1993-02-10T00:00:00.000Z"})",
"optional_timestamp: {seconds: 729302400}");
Expand Down

0 comments on commit 3423d7c

Please sign in to comment.