Skip to content

Fixed bug #52015: Allow including end date in DatePeriod iterations #8550

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

Merged
merged 3 commits into from
May 20, 2022

Conversation

derickr
Copy link
Member

@derickr derickr commented May 13, 2022

Based on a patch by @degeberg (Daniel Egeberg) in https://bugs.php.net/bug.php?id=52015

@derickr derickr requested review from iluuu1994 and Girgias May 13, 2022 13:29
@cmb69
Copy link
Member

cmb69 commented May 13, 2022

Can ::EXCLUDE_START_DATE and ::INCLUDE_END_DATE be used together (as bitmask)? If so, it might be sensible to amend the test case.

Also note that AppVeyor fails because the original base branch had been deleted. I think you need to force-push after rebasing to run on AppVeyor.

@derickr
Copy link
Member Author

derickr commented May 13, 2022

They can be used together, so I will add a test case for that too.

@derickr derickr self-assigned this May 13, 2022
@@ -93,6 +93,7 @@ struct _php_period_obj {
int recurrences;
bool initialized;
bool include_start_date;
int include_end_date;
Copy link
Member

@iluuu1994 iluuu1994 May 13, 2022

Choose a reason for hiding this comment

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

Should't this be a bool? A test for recurrences is missing, I think this would result in one too many iterations. Edit Oh actually that probably doesn't make sense since these two don't go together. Maybe we should inhibit them being used together.

Copy link
Member

Choose a reason for hiding this comment

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

According to @derickr, both can be used together.

Anyhow, consider to use a bitfield here to safe some memory.

Copy link
Member

Choose a reason for hiding this comment

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

@cmb69 I was referring to using recurrences and include_end_date together which I don't think makes sense as recurrences determine the end date. Unless I'm missing something, I'm not familiar with DatePeriod at all.

Copy link
Member

Choose a reason for hiding this comment

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

Ah! And yes, these are mutually exclusive. Still, I think the three bools should be changed to bitfield.

Copy link
Member Author

@derickr derickr May 20, 2022

Choose a reason for hiding this comment

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

I think the patch was originally made when the bool include_start_date was still an int.

recurrences and include_end_date together make no sense, but recurrences and include_start_date could perhaps. I'll have a look at seeing if anything needs addressing/excluding.

initialised should not be part of the bit mask though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now that I have looked this, I am reluctant changing this to a bit mask, due to the negative of "exclude start date". It makes the rest of the code harder to read and understand, so I won't be changing this.

Copy link
Member

Choose a reason for hiding this comment

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

I wasn't referring to a bitmask, but rather a bitfield, i.e.

int initialized:1;
int include_start_date:1;
int include_end_date:1;

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh :-) — I would have hoped the compiler would do with a bool type. But it doesn't. Changing them to bool ...:1 does work, and is IMO prefered over int ...:1:

struct _php_period_obj {
        timelib_time *             start;                /*     0     8 */
        zend_class_entry *         start_ce;             /*     8     8 */
        timelib_time *             current;              /*    16     8 */
        timelib_time *             end;                  /*    24     8 */
        timelib_rel_time *         interval;             /*    32     8 */
        int                        recurrences;          /*    40     4 */
        _Bool                      initialized:1;        /*    44: 0  1 */
        _Bool                      include_start_date:1; /*    44: 1  1 */
        _Bool                      include_end_date:1;   /*    44: 2  1 */

        /* XXX 5 bits hole, try to pack */
        /* XXX 3 bytes hole, try to pack */

        zend_object                std;                  /*    48    56 */

        /* size: 104, cachelines: 2, members: 10 */
        /* sum members: 100, holes: 1, sum holes: 3 */
        /* sum bitfield members: 3 bits, bit holes: 1, sum bit holes: 5 bits */
        /* last cacheline: 40 bytes */
};

Copy link
Member Author

Choose a reason for hiding this comment

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

Although it doesn't actually end up saving memory as the zend_object needs to be aligned to an 8 byte boundary ;-)

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you're right! (Integrating recurrences in the bitfield would be an option, but doesn't look that it's worth it.)

@derickr derickr merged commit f2b7c68 into php:master May 20, 2022
nicolas-grekas added a commit to symfony/symfony that referenced this pull request May 21, 2022
…_date on PHP 8.2 (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[VarDumper][VarExporter] Deal with DatePeriod->include_end_date on PHP 8.2

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Follows php/php-src#8550

Commits
-------

9319a7a [VarDumper][VarExporter] Deal with DatePeriod->include_end_date on PHP 8.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 this pull request may close these issues.

3 participants