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

Issue fork drupal-3585723

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

anybody created an issue. See original summary.

anybody’s picture

Issue summary: View changes
anybody’s picture

Title: #date_year_range handles "0" like relative "+0" / "-0" » #date_year_range handles any value < 1000" like relative "+0" / "-0"
Issue tags: +Novice

It'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?

anybody’s picture

Title: #date_year_range handles any value < 1000" like relative "+0" / "-0" » #date_year_range does not support years < 1000

Okay, I found the root cause:
datetimeRangeYears() does not support years with < 4 digits:

$year_pattern = '@^[0-9]{4}@';

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 0 without +/- prefix. Currently it's always treated as current year!

From Drupal 13 on we should then treat 0 as year 0!

anybody’s picture