Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-39672: [Go] Time to Date32/Date64 conversion issues for non-UTC timezones #39674

Merged
merged 2 commits into from
Jan 18, 2024

Conversation

zeroshade
Copy link
Member

@zeroshade zeroshade commented Jan 17, 2024

A failing unit test in release verification led to discovering an issue with timestamp to date conversions for non-utc timezones.

Upon some investigation I was able to determine that it was the conflation of casting conversion behavior (normalize to cast a Timestamp to a Date) vs flat conversion. I've fixed this conflation of concerns and the version of the methods which are exported properly converts non-UTC timezones to dates without affecting Casting behavior.

Are these changes tested?

yes

Are there any user-facing changes?

The methods Date32FromTime and Date64FromTime will properly handle timezones now.

@zeroshade zeroshade requested a review from raulcd January 17, 2024 22:16
Copy link

⚠️ GitHub issue #39672 has been automatically assigned in GitHub to PR creator.

@github-actions github-actions bot added the awaiting committer review Awaiting committer review label Jan 17, 2024
@zeroshade
Copy link
Member Author

@raulcd this should get cherry-picked into a new RC to fix the failing test

Copy link
Member

@raulcd raulcd left a comment

Choose a reason for hiding this comment

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

Test looks good to me. I am not an expert on go so I am not entirely sure why the changes on datatype_fixedwidth.go are required but as per the test I am ok with the change :)

@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting committer review Awaiting committer review labels Jan 18, 2024
// the actual value by adjusting the time and converting to UTC
t = t.Add(time.Duration(offset) * time.Second).UTC()
}
t = t.In(time.UTC)
Copy link
Member

Choose a reason for hiding this comment

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

Time.Unix() claims it is independent of the location, is this strictly needed?

Copy link
Member

Choose a reason for hiding this comment

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

Since in theory if this change were needed, the adjustment above and the adjustment here would be the same?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, you're absolutely right. I'll update and remove those lines

Comment on lines +132 to +135
if _, offset := tm.Zone(); offset != 0 {
// normalize the tm
tm = tm.Add(time.Duration(offset) * time.Second).UTC()
}
Copy link
Member

Choose a reason for hiding this comment

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

~this is effectively taking a timestamp with timezone and turning it into a naive timestamp showing the date in the former timezone (but marked as UTC)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Because as you pointed out above, when we call .Unix() it returns the result not according to the location but we want it to represent the date in the timezone's location, without having a timezone mark associated. This matches the C++ implementation of the casting in acero (which is where I got the idea)

Copy link
Member

Choose a reason for hiding this comment

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

Ok, cool. This just confuses me since I'm used to Java etc. where these are separate types ^_^

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Jan 18, 2024
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jan 18, 2024
@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting change review Awaiting change review labels Jan 18, 2024
@zeroshade zeroshade merged commit 55afcf0 into apache:main Jan 18, 2024
24 checks passed
@zeroshade zeroshade removed the awaiting merge Awaiting merge label Jan 18, 2024
@zeroshade zeroshade deleted the fix-timezone-handling branch January 18, 2024 20:30
Copy link

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 55afcf0.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 1 possible false positive for unstable benchmarks that are known to sometimes produce them.

clayburn pushed a commit to clayburn/arrow that referenced this pull request Jan 23, 2024
…UTC timezones (apache#39674)

A failing unit test in release verification led to discovering an issue with timestamp to date conversions for non-utc timezones. 

Upon some investigation I was able to determine that it was the conflation of casting conversion behavior (normalize to cast a Timestamp to a Date) vs flat conversion. I've fixed this conflation of concerns and the version of the methods which are exported properly converts non-UTC timezones to dates without affecting Casting behavior.

### Are these changes tested?
yes

### Are there any user-facing changes?
The methods `Date32FromTime` and `Date64FromTime` will properly handle timezones now.

* Closes: apache#39672

Authored-by: Matt Topol <[email protected]>
Signed-off-by: Matt Topol <[email protected]>
dgreiss pushed a commit to dgreiss/arrow that referenced this pull request Feb 19, 2024
…UTC timezones (apache#39674)

A failing unit test in release verification led to discovering an issue with timestamp to date conversions for non-utc timezones. 

Upon some investigation I was able to determine that it was the conflation of casting conversion behavior (normalize to cast a Timestamp to a Date) vs flat conversion. I've fixed this conflation of concerns and the version of the methods which are exported properly converts non-UTC timezones to dates without affecting Casting behavior.

### Are these changes tested?
yes

### Are there any user-facing changes?
The methods `Date32FromTime` and `Date64FromTime` will properly handle timezones now.

* Closes: apache#39672

Authored-by: Matt Topol <[email protected]>
Signed-off-by: Matt Topol <[email protected]>
raulcd pushed a commit that referenced this pull request Feb 20, 2024
…mezones (#39674)

A failing unit test in release verification led to discovering an issue with timestamp to date conversions for non-utc timezones. 

Upon some investigation I was able to determine that it was the conflation of casting conversion behavior (normalize to cast a Timestamp to a Date) vs flat conversion. I've fixed this conflation of concerns and the version of the methods which are exported properly converts non-UTC timezones to dates without affecting Casting behavior.

### Are these changes tested?
yes

### Are there any user-facing changes?
The methods `Date32FromTime` and `Date64FromTime` will properly handle timezones now.

* Closes: #39672

Authored-by: Matt Topol <[email protected]>
Signed-off-by: Matt Topol <[email protected]>
zanmato1984 pushed a commit to zanmato1984/arrow that referenced this pull request Feb 28, 2024
…UTC timezones (apache#39674)

A failing unit test in release verification led to discovering an issue with timestamp to date conversions for non-utc timezones. 

Upon some investigation I was able to determine that it was the conflation of casting conversion behavior (normalize to cast a Timestamp to a Date) vs flat conversion. I've fixed this conflation of concerns and the version of the methods which are exported properly converts non-UTC timezones to dates without affecting Casting behavior.

### Are these changes tested?
yes

### Are there any user-facing changes?
The methods `Date32FromTime` and `Date64FromTime` will properly handle timezones now.

* Closes: apache#39672

Authored-by: Matt Topol <[email protected]>
Signed-off-by: Matt Topol <[email protected]>
thisisnic pushed a commit to thisisnic/arrow that referenced this pull request Mar 8, 2024
…UTC timezones (apache#39674)

A failing unit test in release verification led to discovering an issue with timestamp to date conversions for non-utc timezones. 

Upon some investigation I was able to determine that it was the conflation of casting conversion behavior (normalize to cast a Timestamp to a Date) vs flat conversion. I've fixed this conflation of concerns and the version of the methods which are exported properly converts non-UTC timezones to dates without affecting Casting behavior.

### Are these changes tested?
yes

### Are there any user-facing changes?
The methods `Date32FromTime` and `Date64FromTime` will properly handle timezones now.

* Closes: apache#39672

Authored-by: Matt Topol <[email protected]>
Signed-off-by: Matt Topol <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Go] Time to Date32 / Date64 conversion incorrect for non-UTC timezone
3 participants