class_docstr: A timezone that has a variable offset from UTC
  
  The offset might change if daylight saving time comes into effect,
  or at a point in history when the region decides to change their
  timezone definition.
class_docstr_tok: ["A","timezone","that","has","a","variable","offset","from","UTC","The","offset","might","change","if","daylight","saving","time","comes","into","effect",",","or","at","a","point","in","history","when","the","region","decides","to","change","their","timezone","definition","."]
docstr: Correct the timezone information on the given datetime
  
  If date arithmetic crosses DST boundaries, the tzinfo
  is not magically adjusted. This method normalizes the
  tzinfo to the correct one.
  
  To test, first we need to do some setup
  
  >>> from pytz import timezone
  >>> utc = timezone('UTC')
  >>> eastern = timezone('US/Eastern')
  >>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
  
  We next create a datetime right on an end-of-DST transition point,
  the instant when the wallclocks are wound back one hour.
  
  >>> utc_dt = datetime(2002, 10, 27, 6, 0, 0, tzinfo=utc)
  >>> loc_dt = utc_dt.astimezone(eastern)
  >>> loc_dt.strftime(fmt)
  '2002-10-27 01:00:00 EST (-0500)'
  
  Now, if we subtract a few minutes from it, note that the timezone
  information has not changed.
  
  >>> before = loc_dt - timedelta(minutes=10)
  >>> before.strftime(fmt)
  '2002-10-27 00:50:00 EST (-0500)'
  
  But we can fix that by calling the normalize method
  
  >>> before = eastern.normalize(before)
  >>> before.strftime(fmt)
  '2002-10-27 01:50:00 EDT (-0400)'
  
  The supported method of converting between timezones is to use
  datetime.astimezone(). Currently, normalize() also works:
  
  >>> th = timezone('Asia/Bangkok')
  >>> am = timezone('Europe/Amsterdam')
  >>> dt = th.localize(datetime(2011, 5, 7, 1, 2, 3))
  >>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
  >>> am.normalize(dt).strftime(fmt)
  '2011-05-06 20:02:03 CEST (+0200)'
docstr_tok: ["Correct","the","timezone","information","on","the","given","datetime","If","date","arithmetic","crosses","DST","boundaries",",","the","tzinfo","is","not","magically","adjusted",".","This","method","normalizes","the","tzinfo","to","the","correct","one",".","To","test",",","first","we","need","to","do","some","setup",">",">",">","from","pytz","import","timezone",">",">",">","utc","=","timezone","(","'UTC","'",")",">",">",">","eastern","=","timezone","(","'US\/Eastern","'",")",">",">",">","fmt","=","'","%","Y-","%","m-","%","d","%","H",":","%","M",":","%","S","%","Z","(","%","z",")","'","We","next","create","a","datetime","right","on","an","end-of-DST","transition","point",",","the","instant","when","the","wallclocks","are","wound","back","one","hour",".",">",">",">","utc_dt","=","datetime","(","2002",",","10",",","27",",","6",",","0",",","0",",","tzinfo=utc",")",">",">",">","loc_dt","=","utc_dt.astimezone","(","eastern",")",">",">",">","loc_dt.strftime","(","fmt",")","'2002-10-27","01:00:00","EST","(","-0500",")","'","Now",",","if","we","subtract","a","few","minutes","from","it",",","note","that","the","timezone","information","has","not","changed",".",">",">",">","before","=","loc_dt","-","timedelta","(","minutes=10",")",">",">",">","before.strftime","(","fmt",")","'2002-10-27","00:50:00","EST","(","-0500",")","'","But","we","can","fix","that","by","calling","the","normalize","method",">",">",">","before","=","eastern.normalize","(","before",")",">",">",">","before.strftime","(","fmt",")","'2002-10-27","01:50:00","EDT","(","-0400",")","'","The","supported","method","of","converting","between","timezones","is","to","use","datetime.astimezone","(",")",".","Currently",",","normalize","(",")","also","works",":",">",">",">","th","=","timezone","(","'Asia\/Bangkok","'",")",">",">",">","am","=","timezone","(","'Europe\/Amsterdam","'",")",">",">",">","dt","=","th.localize","(","datetime","(","2011",",","5",",","7",",","1",",","2",",","3",")",")",">",">",">","fmt","=","'","%","Y-","%","m-","%","d","%","H",":","%","M",":","%","S","%","Z","(","%","z",")","'",">",">",">","am.normalize","(","dt",")",".strftime","(","fmt",")","'2011-05-06","20:02:03","CEST","(","+0200",")","'"]
code: def normalize(self, dt):
      """Correct the timezone information on the given datetime
  
      If date arithmetic crosses DST boundaries, the tzinfo
      is not magically adjusted. This method normalizes the
      tzinfo to the correct one.
  
      To test, first we need to do some setup
  
      >>> from pytz import timezone
      >>> utc = timezone('UTC')
      >>> eastern = timezone('US/Eastern')
      >>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
  
      We next create a datetime right on an end-of-DST transition point,
      the instant when the wallclocks are wound back one hour.
  
      >>> utc_dt = datetime(2002, 10, 27, 6, 0, 0, tzinfo=utc)
      >>> loc_dt = utc_dt.astimezone(eastern)
      >>> loc_dt.strftime(fmt)
      '2002-10-27 01:00:00 EST (-0500)'
  
      Now, if we subtract a few minutes from it, note that the timezone
      information has not changed.
  
      >>> before = loc_dt - timedelta(minutes=10)
      >>> before.strftime(fmt)
      '2002-10-27 00:50:00 EST (-0500)'
  
      But we can fix that by calling the normalize method
  
      >>> before = eastern.normalize(before)
      >>> before.strftime(fmt)
      '2002-10-27 01:50:00 EDT (-0400)'
  
      The supported method of converting between timezones is to use
      datetime.astimezone(). Currently, normalize() also works:
  
      >>> th = timezone('Asia/Bangkok')
      >>> am = timezone('Europe/Amsterdam')
      >>> dt = th.localize(datetime(2011, 5, 7, 1, 2, 3))
      >>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
      >>> am.normalize(dt).strftime(fmt)
      '2011-05-06 20:02:03 CEST (+0200)'
      """
      if dt.tzinfo is None:
          raise ValueError("Naive time - no tzinfo set")
  
      # Convert dt in localtime to UTC
      offset = dt.tzinfo._utcoffset
      dt = dt.replace(tzinfo=None)
      dt = dt - offset
      # convert it back, and return it
      return self.fromutc(dt)
  
imports: from datetime import datetime, timedelta, tzinfo
  from bisect import bisect_right
  import pytz
  from pytz.exceptions import AmbiguousTimeError, NonExistentTimeError
label_desc: Use image node_id 3 for calling the DstTzInfo obj's underlying member method code with example usage: obj.normalize(dt) and returns: self