Skip to content

Commit

Permalink
[#2228] Use regexp to replace year
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandar Jovanov committed Jun 28, 2017
1 parent a36de49 commit 05578c8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ckan/lib/helpers.py
Expand Up @@ -1179,12 +1179,16 @@ def render_datetime(datetime_, date_format=None, with_hours=False):

# See http://bugs.python.org/issue1777412
if datetime_.year < 1900:
date_format = date_format.replace('%y', str(datetime_.year)[-2:])
date_format = date_format.replace('%Y', str(datetime_.year))
year = str(datetime_.year)

# "2017" can be any year, since it will be replaced with the one
# provided in "date_format"
datetime_ = datetime.datetime(2017, datetime_.month, datetime_.day,
date_format = re.sub('(?<!%)((%%)*)%y',
r'\g<1>{year}'.format(year=year[-2:]),
date_format)
date_format = re.sub('(?<!%)((%%)*)%Y',
r'\g<1>{year}'.format(year=year),
date_format)

datetime_ = datetime.datetime(2016, datetime_.month, datetime_.day,
datetime_.hour, datetime_.minute,
datetime_.second)

Expand Down

0 comments on commit 05578c8

Please sign in to comment.