Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you call the difference method on the DateObject object and the following criteria are met:
- $date2 parameter is before the date/time represented by the instantiated class (i.e. $this)
- the gap between the dates spans one or more year boundaries
- the $absolute flag is set to FALSE (i.e. we want a negative value out in the current case)
then you end up with an incorrect result. Essentially, the algorithms for adding or subtracting the whole or partial years in between the two dates appear not to take account of the $year_diff < 0 case.
This seems to be the case for week, month and day granularities.
Comment | File | Size | Author |
---|---|---|---|
#1 | fix_for_incorrect_date_difference_arithmetic-1858112-1.patch | 1.89 KB | tomdearden |
Comments
Comment #1
tomdearden CreditAttribution: tomdearden commentedI've made a patch that I think addresses the above issue.
Comment #2
dusov CreditAttribution: dusov commentedPatch works. Thank you.
Comment #3
jamix CreditAttribution: jamix commentedWorks over here, too. Changing status to launch the test bot.
Comment #4
BWPanda CreditAttribution: BWPanda commentedI was having the same problem:
The above code was incorrectly returning a positive value. After applying the patch it correctly returns a negative value. RTBC.
Comment #5
cafuego CreditAttribution: cafuego commentedApplied to 7.x-2.x.