<commit_before>import arrow


def parse_datetime(datetime_input):
    """The arrow library is sadly not good enough to parse
    certain date strings. It even gives unexpected results for partial
    date strings such as '2015-01' or just '2015', which I think
    should be seen as 'the first moment of 2014'.
    This function should overcome those limitations."""
    date_els, time_els = _split_datetime(datetime_input)
    date_vals = _parse_date(date_els)
    time_vals = _parse_time(time_els)
    return arrow.get(*date_vals, *time_vals)    
    

def _split_datetime(datetime_input):
    dt_input = datetime_input.split(" ")
    if len(dt_input) == 1:
        dt_input.append("")
    date_input, time_input = dt_input
    if ":" in date_input:
        date_input, time_input = time_input, date_input
    if not date_input:
        date_input = arrow.now().format("YYYY-MM-DD")
        sep = "-"
    if not time_input:
        time_input = "00:00:00"
    if len(date_input) == 4:
        date_input = "{}-01-01".format(date_input)

    if "/" in date_input:
        sep = "/"
    elif "-" in date_input:
        sep = "-"
    elif "." in date_input:
        sep = "."
    else:
        raise ValueError("Date '{}' can't be understood".format(date_input))
    if time_input and ":" not in time_input:
        raise ValueError("Time '{}' has no ':'-separators".format(time_input))
    return date_input.split(sep), time_input.split(":")


def _parse_date(date_els):
    if len(date_els) == 2:
        # assumed to be year-month or month-year
        a, b = date_els
        if _is_year(a):
            date_vals = a, b, 1  # 1st of month assumed
        elif _is_year(b):
            date_vals = b, a, 1  # 1st of month assumed
        else:
            date_vals = arrow.now().year, a, b  # assumed M/D
    elif len(date_els) == 3:
        # assumed to be year-month-day or month-day-year
        a, b, c = date_els
        if _is_year(a):
            date_vals = a, b, c
        elif _is_year(c):
            date_vals = c, a, b
    else:
        raise ValueError("Date '{}' can't be understood".format(date_els))
    return map(int, date_vals)


def _parse_time(time_els):<commit_msg>fixed bug where '4/11' would be mistaken for a YYYY instead of MM/DD<commit_after>import arrow


def parse_datetime(datetime_input):
    """The arrow library is sadly not good enough to parse
    certain date strings. It even gives unexpected results for partial
    date strings such as '2015-01' or just '2015', which I think
    should be seen as 'the first moment of 2014'.
    This function should overcome those limitations."""
    date_els, time_els = _split_datetime(datetime_input)
    date_vals = _parse_date(date_els)
    time_vals = _parse_time(time_els)
    return arrow.get(*date_vals, *time_vals)    
    

def _split_datetime(datetime_input):
    dt_input = datetime_input.split(" ")
    if len(dt_input) == 1:
        dt_input.append("")
    date_input, time_input = dt_input
    if ":" in date_input:
        date_input, time_input = time_input, date_input
    if not date_input:
        date_input = arrow.now().format("YYYY-MM-DD")
        sep = "-"
    if not time_input:
        time_input = "00:00:00"

    if "/" in date_input:
        sep = "/"
    elif "-" in date_input:
        sep = "-"
    elif "." in date_input:
        sep = "."
    elif len(date_input) == 4:
        date_input = "{}-01-01".format(date_input)  # assume YYYY
        sep = "-"
    else:
        raise ValueError("Date '{}' can't be understood".format(date_input))
    if time_input and ":" not in time_input:
        raise ValueError("Time '{}' has no ':'-separators".format(time_input))
    return date_input.split(sep), time_input.split(":")


def _parse_date(date_els):
    if len(date_els) == 2:
        # assumed to be year-month or month-year
        a, b = date_els
        if _is_year(a):
            date_vals = a, b, 1  # 1st of month assumed
        elif _is_year(b):
            date_vals = b, a, 1  # 1st of month assumed
        else:
            date_vals = arrow.now().year, a, b  # assumed M/D of this year
    elif len(date_els) == 3:
        # assumed to be year-month-day or month-day-year
        a, b, c = date_els
        if _is_year(a):
            date_vals = a, b, c
        elif _is_year(c):
            date_vals = c, a, b
        else:
            raise ValueError("Date '{}' can't be understood".format(date_els))
    else:
        raise ValueError("Date '{}' can't be understood".format(date_els))
    return map(int, date_vals)


def _parse_time(time_els):
{'fraction_non_alphanumeric': 0.11441048034934498, 'fraction_numerical': 0.01462882096069869, 'mean_word_length': 2.4547511312217196, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6490106', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1482, 'n_words': 429}