Skip to content

Commit

Permalink
Use a locale-independent list of month names
Browse files Browse the repository at this point in the history
  • Loading branch information
saimn committed Nov 25, 2020
1 parent 113573f commit 5e32975
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions astropy/utils/iers/iers.py
Expand Up @@ -10,7 +10,6 @@
"""

import re
import locale
from datetime import datetime
from warnings import warn
from urllib.parse import urlparse
Expand Down Expand Up @@ -77,6 +76,9 @@
conf.auto_max_age = None
"""

MONTH_NAMES = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December']


def download_file(*args, **kwargs):
"""
Expand Down Expand Up @@ -1026,20 +1028,16 @@ def expires(self):
def _read_leap_seconds(cls, file, **kwargs):
"""Read a file, identifying expiration by matching 'File expires'"""
expires = None
current = locale.setlocale(locale.LC_TIME)
# Find expiration date.
with get_readable_fileobj(file) as fh:
lines = fh.readlines()
for line in lines:
match = cls._re_expires.match(line)
if match:
try:
locale.setlocale(locale.LC_TIME, 'C')
expires = Time.strptime(match.groups()[0], '%d %B %Y',
scale='tai', format='iso',
out_subfmt='date')
finally:
locale.setlocale(locale.LC_TIME, current)
day, month, year = match.groups()[0].split()
month_nb = MONTH_NAMES.index(month) + 1
expires = Time(f'{year}-{month_nb:02d}-{day}',
scale='tai', out_subfmt='date')
break
else:
raise ValueError(f'did not find expiration date in {file}')
Expand Down

0 comments on commit 5e32975

Please sign in to comment.