from datetime import datetime


def str_to_datetime(dt_str: str) -> datetime:
    """
    Converts a datetime in string format to datetime format.

    Parameters
    ----------
    dt_str : str
        Represents a datetime in string format, "%Y-%m-%d" or "%Y-%m-%d %H:%M:%S"

    Returns
    -------
    datetime
        Represents a datetime in datetime format

    Example
    -------
    >>> from pymove.utils.datetime import str_to_datetime
    >>> time_1 = '2020-06-29'
    >>> time_2 = '2020-06-29 12:45:59'
    >>> print(type(time_1), type(time_2))
    '<class 'str'> <class 'str'>'
    >>> print( str_to_datetime(time_1), type(str_to_datetime(time_1)))
    '2020-06-29 00:00:00 <class 'datetime.datetime'>'
    >>> print(str_to_datetime(time_2), type(str_to_datetime(time_2)))
    '2020-06-29 12:45:59 <class 'datetime.datetime'>'


    """
    if len(dt_str) == 10:
        return datetime.strptime(dt_str, '%Y-%m-%d')
    else:
        return datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S')