from datetime import datetime
import pytz


def date_string_to_datetime(date_string, fmt='%Y-%m-%d', timezone=None):
    """Return a date object for a string of a given format."""
    if isinstance(date_string, datetime):
        return date_string
    try:
        dt = datetime.strptime(date_string, fmt)
    except ValueError:
        # Truncate fractional seconds from string if not included in fmt
        dt = datetime.strptime(date_string.split('.')[0], fmt)

    if timezone:
        tz = pytz.timezone(timezone)
        return tz.localize(dt)
    return dt