import pathlib
import re


def _time_from_filename(name):
    """Parse a time stamp from a file name.

    Parameters
    ----------
    name : str
        File name that contains a time stamp.

    Returns
    -------
    int
        Time stamp from the file name, or ``None`` if no time stamp exists.

    Examples
    --------
    >>> from sequence.cli import _time_from_filename
    >>> _time_from_filename("subsidence-0010.csv")
    10
    >>> _time_from_filename("subsidence.csv") is None
    True
    """
    name = pathlib.Path(name).name

    int_parts = [int(t) for t in re.split("([0-9]+)", name) if t.isdigit()]

    try:
        return int_parts[0]
    except IndexError:
        return None