Problem/Motivation
#date_year_range property handles "0" like relative "+0" / "-0".
In result not year zero is used, but the current year.
Testing to only allow year zero (0):
0:0 // Expected: 0:0, actual: 2026:2026 (current year)
or a range starting in year zero:
0:+50 // Expected: 0:2076, actual: 2026:2076 (current year / current year+50)
Steps to reproduce
See above - to be proven!
Proposed resolution
Write a test to show the issue
Find the bug in
protected static function datetimeRangeYears($string, $date = NULL)
and fix it.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Comments
Comment #2
anybodyComment #3
anybodyIt's even more weird. Entering any value < 1000 leads to current year. Tested with 0, 1 and 999.
Only setting >= 1000 works as expected using the absolute year.
So first we should have tests for this. Maybe a nice little core testing issue for novice?
Comment #5
anybodyOkay, I found the root cause:
datetimeRangeYears()does not support years with < 4 digits:and then magically handles them like relative dates.
Relative dates should always start with a +/-. So current year should be +0, not 0.
If we can't change that without introducing a regression, we should trigger a deprecation error if someone uses
0without +/- prefix. Currently it's always treated as current year!From Drupal 13 on we should then treat
0asyear 0!Comment #6
anybodyComment #8
gwenweb commentedI took the liberty of adding two small improvements to this MR:
Happy to adjust if anything doesn't match the project's standards — this is my first contribution to Drupal core.
Comment #9
anybodyThank you very much @gwenweb!
Comment #10
anybody@gwenweb please see the phpcs issues and the failing test:
Comment #11
gwenweb commentedHi, I'm a relatively new contributor and I hope this is helpful. I've updated the merge request !15503 with the following changes:
The pipeline now passes all 38 jobs. I'm not very experienced with Drupal core contribution standards, so please let me know if anything needs to be adjusted — I'm happy to make changes based on your feedback.
Comment #12
anybodyThanks @gwenweb LGTM! I added some more test case combinations. Are we missing further? Ready for general review I think.
Comment #13
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #14
anybodySorry GitLab had issues...
Comment #15
tstoecklerLooks great to me, nice fix! 14 test cases for this functionality seems fine to me, I don't think this should be held up on trying to conceive of more cases. Let's ship it! 👍️
Comment #16
alexpottCommitted and pushed 4fd9a4ddd56 to main and 248c3ddb05a to 11.x and 8a52c88ba11 to 11.4.x. Thanks!