from typing import List
import calendar
from datetime import datetime
import time


def _dedupe_dates(lst: list, precision: str = "day", tz_aware: bool = False) -> List:
    """Dedupe a given list of date objects
    :param lst: list of date objects
    :param precision: "day" to dedupe upto day (y/m/d) or "time" for y/m/d h:m:s
    :param tz_aware: If true, then dedupe keeping timezones information
    """
    dates_dict = {}
    k = None
    for dt in lst:
        if tz_aware:
            if not dt.tzinfo:
                timestamp = calendar.timegm(dt.timetuple())
                k = datetime.utcfromtimestamp(timestamp)
            else:
                timestamp = time.mktime(dt.timetuple())
                k = datetime.fromtimestamp(timestamp)
        else:
            if precision == "day":
                k = datetime(dt.year, dt.month, dt.day).timestamp()
            elif precision == "time":
                k = datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second).timestamp()

        dates_dict.update({k: dt})

    return list(dates_dict.values())