#7443: timesince template filter reverses its parameters when given a base date
---------------------------------------------------------------------+------
Reporter: Andrew Shearer <[EMAIL PROTECTED]> | Owner:
nobody
Status: reopened |
Milestone:
Component: Template system |
Version: SVN
Resolution: |
Keywords: timesince timeuntil date handling filter
Stage: Ready for checkin |
Has_patch: 1
Needs_docs: 0 |
Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------------------------+------
Changes (by ashearer):
* status: closed => reopened
* resolution: invalid =>
Comment:
I've re-read the documentation, and it seems to clearly contradict the
current behavior. At least two of the three relevant sentences contradict
it, while the remaining sentence supports it. If nothing else, the
documentation should be changed.
But the current behavior still doesn't make much sense. Here's the output
of a test to illustrate that.
{{{
!python
context = {
'now': datetime.now(),
'earlier': datetime.now() - timedelta(days=7),
'later': datetime.now() + timedelta(days=7),
}
}}}
Template output:
* 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
Problem 1: mydate|timesince:now == mydate|timeuntil:now. The two-argument
forms of timesince and timeuntil are synonyms, and therefore redundant.
But their names, documentation, and single-argument forms suggest that
they should give opposite results.
Problem 2: mydate|timesince != mydate|timesince:now. According to its
documentation, 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)." But passing now explicitly as the
comparison point gives opposite results from letting the comparison point
default to now. (The timeuntil documentation contains almost exactly the
same language, but passing now explicitly works the same as letting it
default implicitly.)
Problem 3: The timesince documentation also says that '“0 minutes” will be
returned for any date that is in the future relative to the comparison
point.' The previous paragraph says that the optional argument is the
comparison point. This corresponds to the 'later|timesince:now' line
above, which returns '1 week' instead of the '0 minutes' documented.
In summary, the timesince filter is at best confusing (in which I have
company at ticket #8453) and at worst flies in the face of analogies to
timeuntil, its own single argument form, and two out of the three
sentences of documentation that mention its two-argument form.
(By the way, russelm: the parameter ordering is "slightly" different?
There are only two parameters. Which ordering would rise to the level of
"extremely" different?)
--
Ticket URL: <http://code.djangoproject.com/ticket/7443#comment:5>
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
-~----------~----~----~----~------~----~------~--~---