MCPcopy Index your code
hub / github.com/RustPython/RustPython / checkinside

Method checkinside

Lib/test/datetimetester.py:5646–5695  ·  view source on GitHub ↗
(self, dt, tz, utc, dston, dstoff)

Source from the content-addressed store, hash-verified

5644
5645 # Check a time that's inside DST.
5646 def checkinside(self, dt, tz, utc, dston, dstoff):
5647 self.assertEqual(dt.dst(), HOUR)
5648
5649 # Conversion to our own timezone is always an identity.
5650 self.assertEqual(dt.astimezone(tz), dt)
5651
5652 asutc = dt.astimezone(utc)
5653 there_and_back = asutc.astimezone(tz)
5654
5655 # Conversion to UTC and back isn't always an identity here,
5656 # because there are redundant spellings (in local time) of
5657 # UTC time when DST begins: the clock jumps from 1:59:59
5658 # to 3:00:00, and a local time of 2:MM:SS doesn't really
5659 # make sense then. The classes above treat 2:MM:SS as
5660 # daylight time then (it's "after 2am"), really an alias
5661 # for 1:MM:SS standard time. The latter form is what
5662 # conversion back from UTC produces.
5663 if dt.date() == dston.date() and dt.hour == 2:
5664 # We're in the redundant hour, and coming back from
5665 # UTC gives the 1:MM:SS standard-time spelling.
5666 self.assertEqual(there_and_back + HOUR, dt)
5667 # Although during was considered to be in daylight
5668 # time, there_and_back is not.
5669 self.assertEqual(there_and_back.dst(), ZERO)
5670 # They're the same times in UTC.
5671 self.assertEqual(there_and_back.astimezone(utc),
5672 dt.astimezone(utc))
5673 else:
5674 # We're not in the redundant hour.
5675 self.assertEqual(dt, there_and_back)
5676
5677 # Because we have a redundant spelling when DST begins, there is
5678 # (unfortunately) an hour when DST ends that can't be spelled at all in
5679 # local time. When DST ends, the clock jumps from 1:59 back to 1:00
5680 # again. The hour 1:MM DST has no spelling then: 1:MM is taken to be
5681 # standard time. 1:MM DST == 0:MM EST, but 0:MM is taken to be
5682 # daylight time. The hour 1:MM daylight == 0:MM standard can't be
5683 # expressed in local time. Nevertheless, we want conversion back
5684 # from UTC to mimic the local clock's "repeat an hour" behavior.
5685 nexthour_utc = asutc + HOUR
5686 nexthour_tz = nexthour_utc.astimezone(tz)
5687 if dt.date() == dstoff.date() and dt.hour == 0:
5688 # We're in the hour before the last DST hour. The last DST hour
5689 # is ineffable. We want the conversion back to repeat 1:MM.
5690 self.assertEqual(nexthour_tz, dt.replace(hour=1))
5691 nexthour_utc += HOUR
5692 nexthour_tz = nexthour_utc.astimezone(tz)
5693 self.assertEqual(nexthour_tz, dt.replace(hour=1))
5694 else:
5695 self.assertEqual(nexthour_tz - dt, HOUR)
5696
5697 # Check a time that's outside DST.
5698 def checkoutside(self, dt, tz, utc):

Callers 1

Calls 5

astimezoneMethod · 0.80
dateMethod · 0.80
assertEqualMethod · 0.45
dstMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected