Ticket #17343: tz.diff
File tz.diff, 2.5 KB (added by , 13 years ago) |
---|
-
django/template/defaulttags.py
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 9620d1c..e01e979 100644
a b 2 2 3 3 import sys 4 4 import re 5 from d atetime import datetime5 from django.utils import timezone 6 6 from itertools import groupby, cycle as itertools_cycle 7 7 8 8 from django.conf import settings … … class NowNode(Node): 343 343 self.format_string = format_string 344 344 345 345 def render(self, context): 346 return date( datetime.now(), self.format_string)346 return date(timezone.localtime(timezone.now()), self.format_string) 347 347 348 348 class SpacelessNode(Node): 349 349 def __init__(self, nodelist): -
tests/regressiontests/templates/tests.py
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index e274358..e49d06d 100644
a b class Templates(unittest.TestCase): 504 504 self.assertEqual(failures, [], "Tests failed:\n%s\n%s" % 505 505 ('-'*70, ("\n%s\n" % ('-'*70)).join(failures))) 506 506 507 @override_settings(USE_TZ=True, TIME_ZONE='America/Chicago') 508 def test_now_uses_time_zones(self): 509 from django.utils import timezone 510 with timezone.override('Europe/Warsaw'): 511 template_time = Template('{% now "H:i:s" %}').render(Context()) 512 code_time = timezone.localtime(timezone.now()).strftime('%H:%M:%S') 513 self.assertEqual(template_time, code_time) 514 515 @override_settings(USE_TZ=True, TIME_ZONE='America/Chicago') 516 def test_now_uses_time_zones_and_honors_timezone_tag(self): 517 from django.utils import timezone 518 with timezone.override('Europe/Warsaw'): 519 template_time = Template("""{% load tz %}{% timezone "UTC" %}{% now "H:i:s" %}{% endtimezone %}""").render(Context()) 520 code_time = timezone.now().strftime('%H:%M:%S') 521 self.assertEqual(template_time, code_time) 522 523 @override_settings(USE_TZ=True, TIME_ZONE='America/Chicago') 524 def test_now_uses_time_zones_and_honors_localtime_tag(self): 525 from django.utils import timezone 526 template_time = Template('{% load tz %}{% localtime off %}{% now "H:i:s" %}{% endlocaltime %}').render(Context()) 527 code_time = timezone.now().astimezone(timezone.get_default_timezone()).strftime('%H:%M:%S') 528 self.assertEqual(template_time, code_time) 529 507 530 def render(self, test_template, vals): 508 531 context = template.Context(vals[1]) 509 532 before_stack_size = len(context.dicts)