Skip to content

Add support for -1 as valid year for idate() output.#22657

Merged
derickr merged 3 commits into
php:masterfrom
derickr:bug-gh13273-idate
Jul 10, 2026
Merged

Add support for -1 as valid year for idate() output.#22657
derickr merged 3 commits into
php:masterfrom
derickr:bug-gh13273-idate

Conversation

@derickr

@derickr derickr commented Jul 9, 2026

Copy link
Copy Markdown
Member

Closes GH-13273

Comment thread ext/date/php_date.c
case 'U': retval = (int) t->sse; break;
case 'U': *result = (int) t->sse; break;

default:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The duplicated error handling is a bit ugly.
One way to solve this is have a bool success = true; at the top, then return success; at the bottom, then the default case reduces to success = false;

Comment thread ext/date/php_date.c Outdated
bool ts_is_null = 1;
int ret;
int ret = 0;
bool ok = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just merge the declaration into the assignment line. Reducing variable scopes in general reduces the risk of using (or overwriting) a variable in a place where you shouldn't be able to use it.

@derickr derickr force-pushed the bug-gh13273-idate branch from 84fd759 to a60c8c6 Compare July 10, 2026 12:36
@derickr derickr merged commit 3c15cf1 into php:master Jul 10, 2026
13 of 18 checks passed
Comment thread ext/date/php_date.h
PHPAPI zend_long php_parse_date(const char *string, zend_long *now);
PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, bool gmt);
PHPAPI int php_idate(char format, time_t ts, bool localtime);
PHPAPI bool php_idate(char format, time_t ts, bool localtime, int *result);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change should be listed in UPGRADING.INTERNALS.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh you force pushed this, okay then

@derickr derickr deleted the bug-gh13273-idate branch July 10, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

idate() doesn't work for year -1

2 participants