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 authored and smotornyuk committed Jun 29, 2017
1 parent a9771c0 commit a65c56b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ckan/lib/helpers.py
Expand Up @@ -1163,12 +1163,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 a65c56b

Please sign in to comment.