Django

Code

Ticket #11321 (new)

Opened 8 months ago

Last modified 8 months ago

Bug with humanize and timezones

Reported by: aarond10 Assigned to: nobody
Milestone: Component: Contrib apps
Version: SVN Keywords: humanize, naturalday, timezone
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

Description

Humanize's naturalday filter uses "date.today()" to determine relative dates. This is not valid if you pass it a datetime with the tzinfo field set. The following patch uses a datetime object as an intermediary to correct this behavior.

Attachments

humanize_patch.txt (1.5 kB) - added by aarond10 on 06/15/09 14:04:53.
Patch to humanize.py
11321-r11173.diff (1.2 kB) - added by seocam on 07/03/09 11:13:08.
Patch including some fixes (using svn diff)
11321-r11173-test.diff (2.2 kB) - added by seocam on 07/03/09 11:13:26.
Unit tests
11321-r11173.2.diff (3.4 kB) - added by seocam on 07/03/09 12:27:27.
11321-r11173.3.diff (3.4 kB) - added by seocam on 07/03/09 12:27:58.
Merging tests and patch

Change History

06/15/09 14:04:53 changed by aarond10

  • attachment humanize_patch.txt added.

Patch to humanize.py

06/15/09 18:54:18 changed by russellm

  • needs_better_patch changed.
  • needs_docs changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests set to 1.
  • milestone deleted.

This is annoying, but it isn't critical for v1.1 at this late stage (it doesn't cause data loss, and there are viable workarounds).

Also, the patch needs tests in order to prove that it works.

06/16/09 12:28:10 changed by aarond10ster@gmail.com

Very basic test cases:

from django.contrib.humanize.templatetags.humanize import naturalday from datetime import datetime from pytz import timezone

# Test without timezone (basically the same as existing code)

naturalday(datetime.now())

u'today'

# GMT+9

naturalday(datetime.now(timezone('Asia/Tokyo')))

u'today'

# GMT+2

naturalday(datetime.now(timezone('Europe/Rome')))

u'today'

# GMT+0

naturalday(datetime.now(timezone('UTC')))

u'today'

# GMT-4

naturalday(datetime.now(timezone('America/New_York')))

u'today'

07/03/09 11:13:08 changed by seocam

  • attachment 11321-r11173.diff added.

Patch including some fixes (using svn diff)

07/03/09 11:13:26 changed by seocam

  • attachment 11321-r11173-test.diff added.

Unit tests

07/03/09 12:27:27 changed by seocam

  • attachment 11321-r11173.2.diff added.

07/03/09 12:27:58 changed by seocam

  • attachment 11321-r11173.3.diff added.

Merging tests and patch


Add/Change #11321 (Bug with humanize and timezones)




Change Properties
Action