DateFormatter::formatInterval is really flawed, and how it's being used is also flawed.
It is purporting to format an interval (number of seconds) as a "time ago". But the way it's doing this is:
- Assigning a definite number of seconds to a year, month [actually 30 days in seconds], week, day, hour, minute, and second. This is just wrong for a year or a month; OK for the others.
- Going down the list and comparing the input interval to these values, and using that for formatting.
Some examples of how this goes wrong:
- An interval that's 35 days long, but really represents the interval between May 20 and June 24. This function will say the interval is 1 month and 5 days, but any reasonable person would say it's actually 1 month and 4 days.
- An interval of 35 days, but really represents the interval between Feb 20 and Mar 27. This function will say it is 1 month and 4 days, but it's actually 1 month and 7 days.
- An interval that's from Jan 1 2012 to Jan 1 2013 (366 days), this function will say is a year and a day, but it's really a year.
So. Really, if you want to format an interval correctly, what you need to do is input the two date/time objects you are comparing. You can't do it by inputting a number of seconds, without considering the context of the actual start/end dates, and expect it to be anything reasonable. This function is flawed and meaningless, and needs to be replaced by something more correct.
Date/time stuff is hard...
Beta phase evaluation
Issue category | Bug because date formatting is broken as-is. |
---|---|
Issue priority | Major: the current implementation is wrong since it doesn't take a start- and/or enddate into account, it sometimes returns unexpected results, and core uses this in several places. |
Prioritized changes | Prioritized: The main goal of this issue is fixing a bug in the formatting of date intervals when a start- and/or enddate are known. |
Disruption | None |