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

types: fix STR_TO_DATE handling for %h, %r (#18171) (#18428) #18725

Merged
merged 3 commits into from
Jul 24, 2020

Conversation

ti-srebot
Copy link
Contributor

cherry-pick #18428 to release-3.0


What problem does this PR solve?

Issue Number: close #18171

Problem Summary: Behavior of function STR_TO_DATE is not compatible with MySQL.

  • '%h:%i:%s' parses '12:mm:ss' into '12:mm:ss', which should be '00:mm:ss'.
  • '%r' parses '12:mm:ss AM' into '12:mm:ss' and parses '12:hh:ss PM' into 'NULL'.

What is changed and how it works?

What's Changed:

  • The hour part will change to 0 if '%h' matches 12 and no AM or PM occurs.
  • The hour part will subtract 12 if '%r' matches pattern '12:mm:ss AM' or '12:mm:ss PM'.

How it Works:

  • Function mysqlTimeFix inspects the occurrence of '%h', '%p' and whether the hour part is 12.
  • Function time12Hour now fixes the time when the hour part is 12.

Tests

  • Unit test
  • Manual test

Side effects

No.

Release note

  • types: fix STR_TO_DATE's handling for format token '%r', '%h'

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot
Copy link
Contributor Author

@dyzsr please accept the invitation then you can push to the cherry-pick pull requests.
https://github.com/ti-srebot/tidb/invitations

types/format_test.go Outdated Show resolved Hide resolved
=======
{`12:43:24`, `%h:%i:%s`, types.FromDate(0, 0, 0, 0, 43, 24, 0)},
{`abc`, `abc`, types.ZeroCoreTime},
>>>>>>> cc0b6f1... types: fix STR_TO_DATE handling for %h, %r (#18171) (#18428)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please resolve conflicts. @dyzsr

Copy link
Contributor

@lzmhhh123 lzmhhh123 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 23, 2020
Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 23, 2020
@qw4990
Copy link
Contributor

qw4990 commented Jul 23, 2020

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 23, 2020
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot
Copy link
Contributor Author

@ti-srebot merge failed.

@XuHuaiyu
Copy link
Contributor

/run-unit-test

@XuHuaiyu
Copy link
Contributor

/merge

@ti-srebot
Copy link
Contributor Author

Sorry @XuHuaiyu, you don't have permission to trigger auto merge event on this branch.

@XuHuaiyu
Copy link
Contributor

@qw4990 can merge now

@qw4990
Copy link
Contributor

qw4990 commented Jul 24, 2020

@qw4990 can merge now

I have no permission, PTAL @zz-jason @SunRunAway

@zz-jason
Copy link
Member

/merge

@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot ti-srebot added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Jul 24, 2020
@ti-srebot ti-srebot merged commit 667afd9 into pingcap:release-3.0 Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM. type/compatibility type/3.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants