Ticket #12524: safe_year.2.diff
File safe_year.2.diff, 1.8 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/utils/datetime_safe.py
1 """ 2 >>> from django.utils import datetime_safe 3 4 >>> datetime_safe.date(1850, 8, 2).strftime("%Y/%m/%d was a %A") 5 '1850/08/02 was a Friday' 6 7 # Pre-1900 dates should be padded with zeros if necessary 8 >>> datetime_safe.date(1, 1, 1).strftime("%Y/%m/%d was a %A") 9 '0001/01/01 was a Monday' 10 """ -
tests/regressiontests/utils/tests.py
9 9 10 10 import timesince 11 11 import datastructures 12 import datetime_safe 12 13 import itercompat 13 14 import tzinfo 14 15 … … 26 27 __test__ = { 27 28 'timesince': timesince, 28 29 'datastructures': datastructures, 30 'datetime_safe': datetime_safe, 29 31 'itercompat': itercompat, 30 32 'tzinfo': tzinfo, 31 33 } -
django/utils/datetime_safe.py
4 4 # 5 5 # Based on code submitted to comp.lang.python by Andrew Dalke 6 6 # 7 # >>> datetime_safe.date(1850, 8, 2).strftime("%Y/% M/%d was a %A")7 # >>> datetime_safe.date(1850, 8, 2).strftime("%Y/%m/%d was a %A") 8 8 # '1850/08/02 was a Friday' 9 9 10 10 from datetime import date as real_date, datetime as real_datetime … … 83 83 sites.append(site) 84 84 85 85 s = s1 86 syear = "% 4d" % (dt.year,)86 syear = "%04d" % (dt.year,) 87 87 for site in sites: 88 88 s = s[:site] + syear + s[site+4:] 89 89 return s