Пример #1
0
 def get_time_zone_info():
     """
 @return (int bias, unicode standardName, tuple standardTime, int standardBias,
                    unicode daylightName, tuple daylightTime, int daylightBias)
 """
     # ret: int daylight offset, tz info
     # param: True  use time tuple instead
     _, tzi = win32api.GetTimeZoneInformation(True)
     return tzi
Пример #2
0
    def testFileTimes(self):
        if issubclass(pywintypes.TimeType, datetime.datetime):
            from win32timezone import TimeZoneInfo
            now = datetime.datetime.now(tz=TimeZoneInfo.local())
            nowish = now + datetime.timedelta(seconds=1)
            later = now + datetime.timedelta(seconds=120)
        else:
            rc, tzi = win32api.GetTimeZoneInformation()
            bias = tzi[0]
            if rc == 2:  # daylight-savings is in effect.
                bias += tzi[-1]
            bias *= 60  # minutes to seconds...
            tick = int(time.time())
            now = pywintypes.Time(tick + bias)
            nowish = pywintypes.Time(tick + bias + 1)
            later = pywintypes.Time(tick + bias + 120)

        filename = tempfile.mktemp("-testFileTimes")
        # Windows docs the 'last time' isn't valid until the last write
        # handle is closed - so create the file, then re-open it to check.
        open(filename, "w").close()
        f = win32file.CreateFile(
            filename,
            win32file.GENERIC_READ | win32file.GENERIC_WRITE,
            0,
            None,
            win32con.OPEN_EXISTING,
            0,
            None)
        try:
            ct, at, wt = win32file.GetFileTime(f)
            self.assertTrue(
                ct >= now, "File was created in the past - now=%s, created=%s" %
                (now, ct))
            self.assertTrue(now <= ct <= nowish, (now, ct))
            self.assertTrue(
                wt >= now, "File was written-to in the past now=%s, written=%s" %
                (now, wt))
            self.assertTrue(now <= wt <= nowish, (now, wt))

            # Now set the times.
            win32file.SetFileTime(f, later, later, later)
            # Get them back.
            ct, at, wt = win32file.GetFileTime(f)
            # XXX - the builtin PyTime type appears to be out by a dst offset.
            # just ignore that type here...
            if issubclass(pywintypes.TimeType, datetime.datetime):
                self.assertEqual(ct, later)
                self.assertEqual(at, later)
                self.assertEqual(wt, later)

        finally:
            f.Close()
            os.unlink(filename)
Пример #3
0
 def testTimezone(self):
     # GetTimeZoneInformation
     rc, tzinfo = win32api.GetTimeZoneInformation()
     if rc == win32con.TIME_ZONE_ID_DAYLIGHT:
         tz_str = tzinfo[4]
         tz_time = tzinfo[5]
     else:
         tz_str = tzinfo[1]
         tz_time = tzinfo[2]
     # for the sake of code exercise but don't output
     tz_str.encode()
     tz_time.Format()
Пример #4
0
 def current(class_):
     "Windows Platform SDK GetTimeZoneInformation"
     code, tzi = win32api.GetTimeZoneInformation(True)
     return code, class_(*tzi)
Пример #5
0
	def SetTimeZone(self):
		bias=win32api.GetTimeZoneInformation(True)[1][0]*-1
		hours=bias//60
		minutes=bias%60
		self.timezone=datetime.timezone(datetime.timedelta(hours=hours,minutes=minutes))