internetarchive / internetarchive/openlibrary
Add a better check for published dates when creating a book
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 138
Description
The problem is that when adding a new book to the library, the "When was it published?" doesn't have correct checking of valid dates especially in the days and months fields.
### Evidence / Screenshot (if possible)
### Relevant url?
https://openlibrary.org/books/add
### Steps to Reproduce
1. Go to https://openlibrary.org/books/add
2. Add missing fields and check for dates such as -100/200/2002
* Actual: The field did not show any signs of an invalid output such as when trying with valid but future dates (such as 12/01/2026)
* Expected: An indication of a wrong date
### Details
- **Logged in (Y/N)?** Y
- **Browser type/version?** Safari Version 15.6.1 (17613.3.9.1.16)
- **Operating system?** MacOS
- **Environment (prod/dev/local)?** prod, dev and local
### Proposal & Constraints
Proposed solutions include changing the input to be a scroll wheel with dates or something more friendly for the user or using a regex such as "^(?:-?\d{1,4}|[1-9]\d{3})-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1\d|2[0-8])|(?:0[13-9]|1[0-2])-29|02-(?:0[1-9]|1\d|2[0-9])|02-30|02-31|(?:0[13578]|1[02])-(?:0[1-9]|1\d|2[0-9]|3[01])|(?:0[469]|11)-(?:0[1-9]|1\d|2[0-9]|30))$" to check for the input that could account for the appropriate dates (did not test the regex but I'm pretty sure it is right but does not account for leap years)
Here is an explanation written by chat gpt:
```
^ # Start of the string
(?: # Non-capturing group
-? # Optional minus sign for negative years
\d{1,4} # 1 to 4 digits for the year (allowing both 1 and 4 digit years)
| # OR
[1-9]\d{3} # Match years from 1000 to 9999 (excluding 0000)
)
- # Hyphen separator between year and month
(?: # Non-capturing group for month and day
(?: # Non-capturing group for months with 30 or 31 days
0[1-9]|1[0-2] # Months 01-12
- # Hyphen separator between month and day
0[1-9]|1\d|2[0-8] # Days 01-28
)
| # OR
(?: # Non-capturing group for February
0[13-9]|1[0-2] # Months 03-12
- # Hyphen separator between month and day
29 # Day 29 (allowing leap years)
)
| # OR
02- # February
(?: # Non-capturing group for days 01-28
0[1-9]|1\d|2[0-9] # Days 01-28
)
| # OR
02-30 # Invalid day 30 for February
| # OR
02-31 # Invalid day 31 for February
| # OR
(?: # Non-capturing group for months with 31 days
0[13578]|1[02] # Months 01, 03, 05, 07, 08, 10, 12
- # Hyphen separator between month and day
0[1-9]|1\d|2[0-9]|3[01] # Days 01-31
)
| # OR
(?: # Non-capturing group for months with 30 days
0[469]|11 # Months 04, 06, 09, 11
- # Hyphen separator between month and day
0[1-9]|1\d|2[0-9]|30 # Days 01-30
)
)
$ # End of the string
```
### Related files
### Stakeholders
Contributor guide
Assessment
This issue has not been assessed yet.