import re
from datetime import datetime


def parse_date(xml_datetime):
    """Parse goodread's date into datetime object."""
    if not xml_datetime:
        return None

    # remove timezone info, because python can't properly parse it, at least
    # not without installing additional libraries
    xml_datetime = re.sub(r' (-|\+)?\d{4} ', ' ', xml_datetime)

    return datetime.strptime(xml_datetime, '%a %b %d %H:%M:%S %Y')