How to use the pytz.utc.normalize function in pytz

To help you get started, we’ve selected a few pytz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alangpierce / appengine-python3 / google / appengine / cron / groctimespecification.py View on Github external
tzinfo: a pytz timezone object, or None (interpreted as UTC).

  Returns:
    a datetime object in the time zone 'tzinfo'
  """
  if pytz is None:

    return t.replace(tzinfo=tzinfo)
  elif tzinfo:

    if not t.tzinfo:
      t = pytz.utc.localize(t)
    return tzinfo.normalize(t.astimezone(tzinfo))
  elif t.tzinfo:

    return pytz.utc.normalize(t.astimezone(pytz.utc)).replace(tzinfo=None)
  else:

    return t
github Yelp / Tron / tron / utils / trontimespec.py View on Github external
"""Converts 't' to the time zone 'tzinfo'.

    Arguments:
      t: a datetime object.  It may be in any pytz time zone, or it may be
          timezone-naive (interpreted as UTC).
      tzinfo: a pytz timezone object, or None (interpreted as UTC).

    Returns:
      a datetime object in the time zone 'tzinfo'
    """
    if tzinfo:
        if not t.tzinfo:
            t = pytz.utc.localize(t)
        return tzinfo.normalize(t.astimezone(tzinfo))
    elif t.tzinfo:
        return pytz.utc.normalize(t.astimezone(pytz.utc)).replace(tzinfo=None)
    else:
        return t
github telldus / tellstick-server / scheduler / src / scheduler / base / SchedulerEventFactory.py View on Github external
# even if the temperature rises above 10, don't inactivate the trigger
		# if it's less than 2 hours until departure
		if not self.active:
			return True
		local_timezone = timezone(self.timezone)
		currentDate = pytz.utc.localize(datetime.utcnow())
		local_datetime = local_timezone.localize(
			datetime(currentDate.year, currentDate.month, currentDate.day, self.departureHour, self.departureMinute)
		)
		utc_datetime = pytz.utc.normalize(local_datetime.astimezone(pytz.utc))
		if currentDate > utc_datetime:
			# departure time already passed today
			local_datetime = local_timezone.localize(
				datetime(currentDate.year, currentDate.month, currentDate.day, self.departureHour, self.departureMinute) + timedelta(days=1)
			)
			utc_datetime = pytz.utc.normalize(local_datetime.astimezone(pytz.utc))
		return currentDate < (utc_datetime - timedelta(hours=self.maxRunTime/3600))
github AppScale / appscale / AppServer / google / appengine / cron / groctimespecification.py View on Github external
tzinfo: a pytz timezone object, or None (interpreted as UTC).

  Returns:
    a datetime object in the time zone 'tzinfo'
  """
  if pytz is None:

    return t.replace(tzinfo=tzinfo)
  elif tzinfo:

    if not t.tzinfo:
      t = pytz.utc.localize(t)
    return tzinfo.normalize(t.astimezone(tzinfo))
  elif t.tzinfo:

    return pytz.utc.normalize(t.astimezone(pytz.utc)).replace(tzinfo=None)
  else:

    return t
github GoogleCloudPlatform / python-compat-runtime / google / appengine / cron / groctimespecification.py View on Github external
tzinfo: a pytz timezone object, or None (interpreted as UTC).

  Returns:
    a datetime object in the time zone 'tzinfo'
  """
  if pytz is None:

    return t.replace(tzinfo=tzinfo)
  elif tzinfo:

    if not t.tzinfo:
      t = pytz.utc.localize(t)
    return tzinfo.normalize(t.astimezone(tzinfo))
  elif t.tzinfo:

    return pytz.utc.normalize(t.astimezone(pytz.utc)).replace(tzinfo=None)
  else:

    return t
github djblets / djblets / djblets / datagrid / grids.py View on Github external
def render_data(self, state, obj):
        # If the datetime object is tz aware, conver it to local time
        datetime = getattr(obj, self.field_name)
        if settings.USE_TZ:
            datetime = pytz.utc.normalize(datetime).\
                astimezone(self.timezone)

        return date(datetime, self.format)
github beda-software / fhir-py / fhirpy / base / searchset.py View on Github external
def format_date_time(date: datetime.datetime):
    return pytz.utc.normalize(date).strftime(FHIR_DATE_TIME_FORMAT)
github horazont / aioxmpp / aioxmpp / xso / types.py View on Github external
def format(self, v):
        if v.tzinfo:
            v = pytz.utc.normalize(v)

        result = v.strftime("%H:%M:%S")
        if v.microsecond:
            result += ".{:06d}".format(v.microsecond).rstrip("0")
        if v.tzinfo:
            result += "Z"
        return result
github guokr / asynx / asynx-core / asynx_core / taskqueue.py View on Github external
def last_run_at(self, val):
        if val:
            val = utc.normalize(val)
        self._last_run_at = val