Skip to content

replication: return string when datetime's day or month is 00 #1047

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

Merged
merged 4 commits into from
Jul 6, 2025

Conversation

serprex
Copy link
Contributor

@serprex serprex commented Jul 3, 2025

MySQL supports 0 for day/month when this is an unknown value

This cannot be encoded into a time.Time, where time.Date normalizes these 0s (so 2000-00-00 would become 1999-11-30)

Pass these values through in their raw string form instead, like we do for 0000-00-00

MySQL supports 0 for day/month when this is an unknown value

This cannot be encoded into a time.Time, where time.Date normalizes these 0s
(so 2000-00-00 would become 1999-11-30)

Pass these values through in their raw string form instead
@lance6716 lance6716 requested a review from Copilot July 4, 2025 00:57
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates datetime decoding to preserve zero-valued months or days by returning raw strings instead of normalizing via time.Time.

  • Introduces a parseTime flag in decodeDatetime2 and RowsEvent.decodeValue to control string fallback for 00 month/day.
  • Renames formatBeforeUnixZeroTime to formatDatetime for unified formatting.
  • Adds new tests covering zero‐month/day behavior and adjusts the test harness to iterate parse settings.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
replication/time.go Renamed formatBeforeUnixZeroTime to formatDatetime.
replication/row_event.go Updated decodeValue and decodeDatetime2 to use parseTime; handle month==0/day==0 by string.
replication/row_event_test.go Extended TestDecodeDatetime2 to loop over both parseTime modes and test zero-month/day cases.
Comments suppressed due to low confidence (1)

replication/row_event_test.go:689

  • Add test cases with fractional seconds (dec > 0) when month or day is zero to verify that fractional parts are preserved in the string output.
		for _, parseTime := range []bool{true, false} {

@lance6716
Copy link
Collaborator

Thanks! I'll start review about 24hrs later.

Copy link
Collaborator

@dveeden dveeden left a comment

Choose a reason for hiding this comment

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

Seems fine. But I only glanced over it.

@lance6716 lance6716 merged commit 4a082cf into go-mysql-org:master Jul 6, 2025
18 checks passed
serprex added a commit to PeerDB-io/peerdb that referenced this pull request Jul 6, 2025
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