def parse_date_pattern()

in curator/helpers/date_ops.py [0:0]


def parse_date_pattern(name):
    """
    Scan and parse ``name`` for :py:func:`~.time.strftime` strings, replacing them with
    the associated value when found, but otherwise returning lowercase values, as
    uppercase snapshot names are not allowed. It will detect if the first character is
    a ``<``, which would indicate ``name`` is going to be using Elasticsearch date math
    syntax, and skip accordingly.

    The :py:func:`~.time.strftime` identifiers that Curator currently recognizes as
    acceptable include:

    * ``Y``: A 4 digit year
    * ``y``: A 2 digit year
    * ``m``: The 2 digit month
    * ``W``: The 2 digit week of the year
    * ``d``: The 2 digit day of the month
    * ``H``: The 2 digit hour of the day, in 24 hour notation
    * ``M``: The 2 digit minute of the hour
    * ``S``: The 2 digit number of second of the minute
    * ``j``: The 3 digit day of the year

    :param name: A name, which can contain :py:func:`~.time.strftime` strings
    :type name: str

    :returns: The parsed date pattern
    :rtype: str
    """
    logger = logging.getLogger(__name__)
    prev, rendered = ('', '')
    logger.debug('Provided index name: %s', name)
    for idx, char in enumerate(name):
        logger.debug('Current character in provided name: %s, position: %s', char, idx)
        if char == '<':
            logger.info('"%s" is probably using Elasticsearch date math.', name)
            rendered = name
            break
        if char == '%':
            pass
        elif char in date_regex() and prev == '%':
            rendered += str(datetime.now(timezone.utc).strftime(f'%{char}'))
        else:
            rendered += char
        logger.debug('Partially rendered name: %s', rendered)
        prev = char
    logger.debug('Fully rendered name: %s', rendered)
    return rendered