in curator/helpers/date_ops.py [0:0]
def get_datetime(index_timestamp, timestring):
"""
:param index_timestamp: The index timestamp
:param timestring: An ``strftime`` pattern
:type index_timestamp: str
:type timestring: :py:func:`~.time.strftime`
:returns: The datetime extracted from the index name, which is the index creation
time.
:rtype: :py:class:`~.datetime.datetime`
"""
# Compensate for week of year by appending '%w' to the timestring
# and '1' (Monday) to index_timestamp
iso_week_number = False
if '%W' in timestring or '%U' in timestring or '%V' in timestring:
timestring += '%w'
index_timestamp += '1'
if '%V' in timestring and '%G' in timestring:
iso_week_number = True
# Fake as so we read Greg format instead. We will process it later
timestring = timestring.replace("%G", "%Y").replace("%V", "%W")
elif '%m' in timestring:
if '%d' not in timestring:
timestring += '%d'
index_timestamp += '1'
mydate = datetime.strptime(index_timestamp, timestring)
# Handle ISO time string
if iso_week_number:
mydate = handle_iso_week_number(mydate, timestring, index_timestamp)
return mydate