Ticket #12524: safe_year.2.diff

File safe_year.2.diff, 1.8 KB (added by Gabriel Farrell, 15 years ago)

now with test

  • 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

     
    99
    1010import timesince
    1111import datastructures
     12import datetime_safe
    1213import itercompat
    1314import tzinfo
    1415
     
    2627__test__ = {
    2728    'timesince': timesince,
    2829    'datastructures': datastructures,
     30    'datetime_safe': datetime_safe,
    2931    'itercompat': itercompat,
    3032    'tzinfo': tzinfo,
    3133}
  • django/utils/datetime_safe.py

     
    44#
    55# Based on code submitted to comp.lang.python by Andrew Dalke
    66#
    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")
    88# '1850/08/02 was a Friday'
    99
    1010from datetime import date as real_date, datetime as real_datetime
     
    8383            sites.append(site)
    8484
    8585    s = s1
    86     syear = "%4d" % (dt.year,)
     86    syear = "%04d" % (dt.year,)
    8787    for site in sites:
    8888        s = s[:site] + syear + s[site+4:]
    8989    return s
Back to Top