I have had an issue on several things now with date not accounting for leap year.
Calendars have been off, age is incorrect etc.
Most recently I have used Views timeago selector and date of birth field. For every 4-7 years of age the age is off by 1 day cumulatively.
Example.
Age 5 is off by 1 day
Age 9 is off by 2 days
Age 13 is off by 3 days etc.
At first I thought it was Views but tracing it back, it looks like it is the DATE module. I am not a programmer, but it looks like it may be differences in date & dateTime or perhaps dateInterval. I would love to be able to fix it myself but I am afraid I would break more than I fix.
Does anyone have a solution for this issue?
TIA
Comment | File | Size | Author |
---|---|---|---|
#14 | 2875478-14.patch | 4.12 KB | kunal_sahu |
#11 | date-n2875478-10-tests-only.patch | 3.8 KB | DamienMcKenna |
#10 | interdiff_8-10.txt | 4.37 KB | Ronino |
#10 | date-core-format-interval-works-wrong-2875478-10.patch | 9.52 KB | Ronino |
| |||
#8 | interdiff_7-8.txt | 1.03 KB | Ronino |
Issue fork date-2875478
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
Comment #2
garymullins CreditAttribution: garymullins commentedIs no one else having a problem with this?
Is there a fix I am missing?
I have searched and have not found a solution. If one exist, can you point me in the right directions?
Thanks in advance
Comment #3
lodey CreditAttribution: lodey commentedI also am having this issue. Looking around I also found this post - looks like the date module is not allowing for leap years. I have no solution yet, but may just find another way to display this info for my use case.
Comment #4
Andrew Dolgov CreditAttribution: Andrew Dolgov commentedcore format_interval function works wrong, re-implemented with date alternative function, that use date->diff() and two calendar points, not interval in seconds
Comment #6
DamienMcKennaI appreciate you taking the time to work on a patch for this. However, the PHP 5.3 tests fail, so at the very least it can't be committed as-is.
Comment #7
Ronino CreditAttribution: Ronino commentedI reworked patch #4:
I can't really provide an interdiff as #4 fails to apply.
This not only affects leap years, but intervals in general. Like @Andrew correctly stated, the reason is core's format_interval() which only knows about the interval in seconds, but not about the dates. So with the fix, for example the difference between Jan 1st and Feb 1st as well as Feb 1st and Mar 1st is both "1 month" while format_interval() would return "1 month 1 day" and "4 weeks" (i.e. 28 days) respectively.
Comment #8
Ronino CreditAttribution: Ronino commentedI improved #7 to only compare actual dates if the given date doesn't have a time set. So the difference between now and tomorrow is "1 day" and not e.g. "8 hours" if it's 4 p.m.
Comment #9
DamienMcKennaThis is great, thank you.
I think we really need to have test coverage, just to make sure the logic works as expected and ensure we don't run into regressions later on.
Comment #10
Ronino CreditAttribution: Ronino commentedThis patch adds tests.
Some tests can fail though and I'm not sure how to handle this (see DateApiTestCase::testDateInterval()): Any interval that contains fractions of a day (e.g. 1 hour) will fail if the current time is that interval before midnight (e.g. 23:00:00). This is due to the constructor of DateObject considering any date with a time of 00:00:00 as "dateOnly", resulting in a "1 day" interval instead of "1 hour" as the times are ignored.
I tested them at different times using the timecop PHP extension (https://github.com/kiddivouchers/php-timecop):
The tests revealed that it makes a difference (pun intended) for DateTime::diff() in what order the dates are used. I fixed this in _date_format_interval().
Comment #11
DamienMcKennaThat's great work, Ronino!
Here's the tests on their own to hopefully confirm the problem, i.e. this should fail.
Comment #14
kunal_sahu CreditAttribution: kunal_sahu at Valuebound for Valuebound commentedPlease review this patch . Hope this passes the test.
Thanks
Comment #16
kunal_sahu CreditAttribution: kunal_sahu at Valuebound for Valuebound commentedComment #17
kunal_sahu CreditAttribution: kunal_sahu at Valuebound for Valuebound commentedPlease ignore #14 Patch.