#8453: Error in filter "timesince"
--------------------------------------+-------------------------------------
Reporter: carlou | Owner: jheasly
Status: reopened | Milestone: 1.0
Component: Template system | Version: 1.0-beta-1
Resolution: | Keywords: timesince
Stage: Accepted | Has_patch: 0
Needs_docs: 0 | Needs_tests: 1
Needs_better_patch: 0 |
--------------------------------------+-------------------------------------
Changes (by ashearer):
* status: closed => reopened
* resolution: invalid =>
Comment:
I'd agree that the current behavior is surprising, but I'd also say that
it contradicts the documentation. Or two out of its three relevant
sentences. See #7443:comment:5 for details.
Am I reading incorrectly? I can't believe I've misread it this many times
in a row.
Here's the current behavior (where 'earlier' is a week behind 'now' and
'later' is a week ahead):
* earlier|timesince: 1 week
* earlier|timesince:now: 0 minutes
* earlier|timeuntil: 0 minutes
* earlier|timeuntil:now: 0 minutes
* later|timesince: 0 minutes
* later|timesince:now: 1 week
* later|timeuntil: 1 week
* later|timeuntil:now: 1 week
The first full sentence of the
[http://www.djangoproject.com/documentation/templates/ documentation] says
timesince "[t]akes an optional argument that is a variable containing the
date to use as the comparison point (without the argument, the comparison
point is now)." However, passing now explicitly as the optional argument
leads to results opposite to allowing it to be the default.
The last sentence says '“0 minutes” will be returned for any date that is
in the future relative to the comparison point'. According to the first
sentence, that corresponds to the 'later|timesince:now' test, which
returns '1 week' instead.
The middle sentence, giving an example, seems to contradict the other two.
If this apparent conflict is resolved in favor of having
mydate|timesince:now act like mydate|timesince (obviously the approach I
favor), 2/3 of the documentation and the analogy with timeuntil already
agree. The only hangup would be existing code. But I'd wonder how
widespread that is for the two-argument version. Anyone surprised by the
behavior or who realized the documentation didn't entirely match the
results could have steered clear by swapping arguments and using two-
argument timeuntil instead, which is currently an exact synonym of
timesince, but matches its own English meaning and its documentation. In
any case, if it's going to change to a less surprising behavior someday,
the backward compatibility argument points to getting it in by 1.0.
More discussion, a patch, and test cases in #7443.
--
Ticket URL: <http://code.djangoproject.com/ticket/8453#comment:4>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---