Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

bug: fix year formatting in spanner::Date #1085

Merged
merged 2 commits into from
Nov 19, 2019
Merged

bug: fix year formatting in spanner::Date #1085

merged 2 commits into from
Nov 19, 2019

Conversation

coryan
Copy link
Contributor

@coryan coryan commented Nov 19, 2019

The year is required to be 0-padded to 4 digits, the month and date
padding seems to be optional.

Introduce a new integration test to verify data types can be written and
read back.

Fixes #1083


This change is Reviewable

The year is required to be 0-padded to 4 digits, the month and date
padding seems to be optional.

Introduce a new integration test to verify data types can be written and
read back.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 19, 2019
@codecov
Copy link

codecov bot commented Nov 19, 2019

Codecov Report

Merging #1085 into master will decrease coverage by 0.29%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1085     +/-   ##
=========================================
- Coverage   92.02%   91.72%   -0.3%     
=========================================
  Files         163      164      +1     
  Lines       11995    12022     +27     
=========================================
- Hits        11038    11027     -11     
- Misses        957      995     +38
Impacted Files Coverage Δ
google/cloud/spanner/internal/date_test.cc 100% <ø> (ø) ⬆️
...ogle/cloud/spanner/testing/database_environment.cc 92% <100%> (ø) ⬆️
...r/integration_tests/data_types_integration_test.cc 100% <100%> (ø)
google/cloud/spanner/internal/date.cc 100% <100%> (ø) ⬆️
.../spanner/benchmarks/multiple_rows_cpu_benchmark.cc 72.16% <0%> (-7.35%) ⬇️
google/cloud/spanner/internal/polling_loop.h 91.89% <0%> (-2.71%) ⬇️
google/cloud/spanner/internal/spanner_stub.cc 68.13% <0%> (-2.2%) ⬇️
google/cloud/spanner/client.cc 82.69% <0%> (-0.97%) ⬇️
...ud/spanner/integration_tests/client_stress_test.cc 82.45% <0%> (-0.88%) ⬇️
...on_tests/rpc_failure_threshold_integration_test.cc 85.55% <0%> (-0.16%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 488c88d...d722690. Read the comment docs.

@coryan coryan marked this pull request as ready for review November 19, 2019 17:21
@@ -25,7 +25,7 @@ namespace internal {

std::string DateToString(Date d) {
std::array<char, sizeof "-9223372036854775808-01-01"> buf;
std::snprintf(buf.data(), buf.size(), "%" PRId64 "-%02d-%02d", d.year(),
std::snprintf(buf.data(), buf.size(), "%04" PRId64 "-%02d-%02d", d.year(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem.

"INSERT INTO DataTypes (Id, DateValue, StringValue) "
"VALUES(@id, @date, @event)",
{{"id", Value("ReadWriteDate-1")},
{"date", Value(Date(161, 3, 8))},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should add a "> 9999" case to see how they handle their "YYYY: Four-digit year" edict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything over 9999 results in an error. That is consistent with the documentation; which says the valid range is 0001-01-01 to 9999-12-31

@coryan coryan merged commit 5e6c913 into googleapis:master Nov 19, 2019
@coryan coryan deleted the fix-year-formatting-for-dates branch November 19, 2019 18:38
devjgm pushed a commit to devjgm/google-cloud-cpp that referenced this pull request May 7, 2020
…p-spanner#1085)

The year is required to be 0-padded to 4 digits, the month and date
padding seems to be optional.

Introduce a new integration test to verify data types can be written and
read back.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pad years to 4 digits in spanner::Date objects.
3 participants