Skip to content

ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup#2609

Open
lszskye wants to merge 6 commits intoapache:mainfrom
lszskye:fix_ts
Open

ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup#2609
lszskye wants to merge 6 commits intoapache:mainfrom
lszskye:fix_ts

Conversation

@lszskye
Copy link
Copy Markdown

@lszskye lszskye commented Apr 22, 2026

What changes were proposed in this pull request?

Moving the compensation to before the timezone conversion, we ensure that getVariant() always receives the corrected wall-clock time, producing the correct DST offset and an accurate final result.

Why are the changes needed?

Previously, the -1 second compensation for pre-1970 timestamps was applied after the writer-to-reader timezone adjustment. This means writerTimezone.getVariant(writerTime) was called with an uncorrected writerTime that could be 1 second larger than the true value. If this 1-second discrepancy happens to cross a DST (Daylight Saving Time) boundary, the timezone lookup would return an incorrect GMT offset, causing the final timestamp result to be off by the entire DST shift (typically 1 hour) rather than just 1 second.

Was this patch authored or co-authored using generative AI tooling?

No

Copy link
Copy Markdown
Member

@wgtmac wgtmac left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this! Is it possible to add a test case?

@lszskye lszskye closed this Apr 22, 2026
@lszskye lszskye reopened this Apr 22, 2026
Copy link
Copy Markdown
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, LGTM, too. Also, I agree with the above comment about the test coverage.

@lszskye
Copy link
Copy Markdown
Author

lszskye commented Apr 23, 2026

Thanks for fixing this! Is it possible to add a test case?

OK, let me add a unit test for this change.

@ffacs ffacs changed the title ORC-2151: Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup Apr 23, 2026
@lszskye
Copy link
Copy Markdown
Author

lszskye commented Apr 27, 2026

@wgtmac All tests have passed. Please help merge. Thanks!

Comment thread c++/test/TestWriter.cc
// -1 BEFORE timezone conversion so that getVariant() sees -5756401 (PDT).
// If compensation were applied AFTER timezone conversion, getVariant() would
// see -5756400 (PST), producing a gmtOffset that differs by 3600 seconds.
TEST_P(WriterTest, DISABLED_writeNegativeTimestampAtDSTBoundary) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is it DISABLED?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I added DISABLED_ to keep it consistent with the other timestamp-related tests in the same file (DISABLED_writeTimestamp, DISABLED_writeNegativeTimestamp, DISABLED_writeTimestampWithTimezone, DISABLED_writeTimestampInstant), which are all disabled due to [ORC-1976]. Also, I'm happy to remove the DISABLED_ prefix if you prefer — please let me know.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, it would be great if these can be fixed together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants