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

Incorrect date parsing for year 1-999 #9230

Closed
a88zach opened this issue Jul 21, 2022 · 0 comments · Fixed by #9236
Closed

Incorrect date parsing for year 1-999 #9230

a88zach opened this issue Jul 21, 2022 · 0 comments · Fixed by #9236

Comments

@a88zach
Copy link
Contributor

a88zach commented Jul 21, 2022

Issue Description

There is an edge case with very early years where the date parsing logic is incorrect. The code here does not handle years 1-999 correctly: https://github.com/typeorm/typeorm/blob/51b2a63d/src/util/DateUtils.ts#L25

As an example, if the date stored in the database is 0202-01-01 which is a valid date, the output from parsing will be 202-01-01. This format breaks validation when returning a response if validation requires a valid ISO date format

Expected Behavior

A date from year 1 to year 999 should contain a leading 0 when parsed from the database

Actual Behavior

The leading 0 is being stripped from the date

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres yes
react-native no
sap no
spanner no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✅ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
a88zach pushed a commit to a88zach/typeorm that referenced this issue Jul 22, 2022
pleerock pushed a commit that referenced this issue Aug 24, 2022
* fix: update date utils to parse year correctly for years 1-999

Closes: #9230

* fix: commit change to date utils

* fix: default total length to 2
wirekang pushed a commit to wirekang/typeorm that referenced this issue Aug 25, 2022
…rm#9236)

* fix: update date utils to parse year correctly for years 1-999

Closes: typeorm#9230

* fix: commit change to date utils

* fix: default total length to 2
nordinh pushed a commit to nordinh/typeorm that referenced this issue Aug 29, 2022
…rm#9236)

* fix: update date utils to parse year correctly for years 1-999

Closes: typeorm#9230

* fix: commit change to date utils

* fix: default total length to 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant