Page MenuHomePhabricator

#time function returns incorrect value if asked for previous month
Closed, DeclinedPublic

Description

The function {{#time:F|-1 months}} returns current month's name in place of previous month.

Please see the screenshot. The function {{#time:F|-1 months}} returns current month's name in place of previous month.


Version: unspecified
Severity: minor

Attached:

screenshot.png (463×554 px, 22 KB)

Details

Reference
bz49007

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:45 AM
bzimport added a project: ParserFunctions.
bzimport set Reference to bz49007.
bzimport added a subscriber: Unknown Object (MLST).

The screenshot was taken from English Wikipedia.

I'm not sure this is a bug: "May 31 - 1 months" is "April 31", which is "May 1".

Just some examples (with format c, to show the whole date):

{{#time:c}}           = 2013-05-31T09:24:00+00:00
{{#time:c|-1 months}} = 2013-05-01T09:24:00+00:00
{{#time:c|-2 months}} = 2013-03-31T09:24:00+00:00
{{#time:c|-3 months}} = 2013-03-03T09:24:00+00:00

So {{#time:F|-1 months}} = May is strange, but consistent.

http://www.gnu.org/software/tar/manual/html_node/Relative-items-in-date-strings.html#SEC125:

"The fuzz in units can cause problems with relative items. For example, ‘2003-07-31 -1 month’ might evaluate to 2003-07-01, because 2003-06-31 is an invalid date. To determine the previous month more reliably, you can ask for the month before the 15th of the current month."

Maybe {{#time:F|2000-{{#expr:{{#time:m}}-1}}-1}}?

Lowering the priority to minor. If it is not at all a bug, it may please be closed.

I don't think this is fixable – as Michael explained, it's a quirky, but expected behavior. Closing.