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 checkMonthDay() to correctly handle leap year #10342

Merged
merged 4 commits into from
May 5, 2019

Conversation

erjiaqing
Copy link
Contributor

@erjiaqing erjiaqing commented May 5, 2019

What problem does this PR solve?

1900-02-29 is not a valid date. However:

In TiDB:

mysql> insert into t1 values ("1900-02-29 00:00:00");
Query OK, 1 row affected (0.00 sec)

MySQL does not consider 1900 as a leap year. So this is not intended.

In MySQL:

mysql> insert into t1 values ("1900-02-29 00:00:00");
ERROR 1292 (22007): Incorrect datetime value: '1900-02-29 00:00:00' for column 't' at row 1

What is changed and how it works?

if month == 2 && !isLeapYear(uint16(year)) {
	maxDay = 28
}

Check List

Tests

  • Unit test

@erjiaqing erjiaqing added the type/bugfix This PR fixes a bug. label May 5, 2019
@codecov
Copy link

codecov bot commented May 5, 2019

Codecov Report

Merging #10342 into master will decrease coverage by 0.0189%.
The diff coverage is 100%.

@@               Coverage Diff               @@
##             master     #10342       +/-   ##
===============================================
- Coverage   77.6767%   77.6578%   -0.019%     
===============================================
  Files           411        411               
  Lines         85440      85390       -50     
===============================================
- Hits          66367      66312       -55     
- Misses        14112      14116        +4     
- Partials       4961       4962        +1

@codecov
Copy link

codecov bot commented May 5, 2019

Codecov Report

Merging #10342 into master will increase coverage by 0.01%.
The diff coverage is 100%.

@@              Coverage Diff               @@
##             master     #10342      +/-   ##
==============================================
+ Coverage   77.6662%   77.6762%   +0.01%     
==============================================
  Files           411        411              
  Lines         85440      85389      -51     
==============================================
- Hits          66358      66327      -31     
+ Misses        14118      14103      -15     
+ Partials       4964       4959       -5

@zhouqiang-cl
Copy link
Contributor

/rebuild

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@lysu lysu added the status/LGT1 Indicates that a PR has LGTM 1. label May 5, 2019
@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 5, 2019
@zz-jason
Copy link
Member

zz-jason commented May 5, 2019

/run-all-tests

@zz-jason zz-jason changed the title types: Fix types.Time.Check() on year 1900 types: Fix checkMonthDay() to correctly handle leap year May 5, 2019
@zz-jason zz-jason merged commit c9f0a1c into pingcap:master May 5, 2019
@zz-jason
Copy link
Member

zz-jason commented May 5, 2019

@erjiaqing please cherry pick this bug-fix to release-2.1

@erjiaqing erjiaqing deleted the fix-leap-year branch May 5, 2019 11:39
erjiaqing added a commit to erjiaqing/tidb that referenced this pull request May 10, 2019
@sre-bot sre-bot added the contribution This PR is from a community contributor. label Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants