Ejemplo n.º 1
0
    def _date_to_str(self, dt: datetime.date, fmt="%Y-%m-%dT%H:%M:%SZ"):
        if isinstance(dt, datetime.datetime):
            if not dt.tzinfo:
                dt = self.timezone.localize(dt)
            dt = dt.astimezone(self.timezone)
        elif isinstance(dt, datetime.date):
            dt = datetime.datetime(year=dt.year,
                                   month=dt.month,
                                   day=dt.day,
                                   tzinfo=self.timezone)

        return dt.strftime(fmt)
Ejemplo n.º 2
0
def to_utc(value: date) -> date:
    if isinstance(value, datetime):
        return value.astimezone(timezone.utc).replace(tzinfo=None)
    return value