• Home
  • Raw
  • Download

Lines Matching full:time

10 import time
54 self.t = time.time()
57 time.altzone
58 time.daylight
59 time.timezone
60 time.tzname
63 time.time()
64 info = time.get_clock_info('time')
76 check_ns(time.time(),
77 time.time_ns())
78 check_ns(time.monotonic(),
79 time.monotonic_ns())
80 check_ns(time.perf_counter(),
81 time.perf_counter_ns())
82 check_ns(time.process_time(),
83 time.process_time_ns())
85 if hasattr(time, 'thread_time'):
86 check_ns(time.thread_time(),
87 time.thread_time_ns())
89 if hasattr(time, 'clock_gettime'):
90 check_ns(time.clock_gettime(time.CLOCK_REALTIME),
91 time.clock_gettime_ns(time.CLOCK_REALTIME))
93 @unittest.skipUnless(hasattr(time, 'clock_gettime'),
94 'need time.clock_gettime()')
96 t = time.clock_gettime(time.CLOCK_REALTIME)
99 @unittest.skipUnless(hasattr(time, 'clock_gettime'),
100 'need time.clock_gettime()')
101 @unittest.skipUnless(hasattr(time, 'CLOCK_MONOTONIC'),
102 'need time.CLOCK_MONOTONIC')
104 a = time.clock_gettime(time.CLOCK_MONOTONIC)
105 b = time.clock_gettime(time.CLOCK_MONOTONIC)
108 @unittest.skipUnless(hasattr(time, 'pthread_getcpuclockid'),
109 'need time.pthread_getcpuclockid()')
110 @unittest.skipUnless(hasattr(time, 'clock_gettime'),
111 'need time.clock_gettime()')
113 clk_id = time.pthread_getcpuclockid(threading.get_ident())
117 self.assertEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
120 self.assertEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
122 self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
123 t1 = time.clock_gettime(clk_id)
124 t2 = time.clock_gettime(clk_id)
127 @unittest.skipUnless(hasattr(time, 'clock_getres'),
128 'need time.clock_getres()')
130 res = time.clock_getres(time.CLOCK_REALTIME)
134 @unittest.skipUnless(hasattr(time, 'clock_settime'),
135 'need time.clock_settime()')
137 t = time.clock_gettime(time.CLOCK_REALTIME)
139 time.clock_settime(time.CLOCK_REALTIME, t)
143 if hasattr(time, 'CLOCK_MONOTONIC'):
145 time.clock_settime, time.CLOCK_MONOTONIC, 0)
148 self.assertEqual(time.ctime(self.t),
149 time.asctime(time.localtime(self.t)))
150 self.assertEqual(int(time.mktime(time.localtime(self.t))),
154 self.assertRaises(ValueError, time.sleep, -2)
155 self.assertRaises(ValueError, time.sleep, -1)
156 time.sleep(1.2)
159 tt = time.gmtime(self.t)
165 time.strftime(format, tt)
169 self.assertRaises(TypeError, time.strftime, b'%S', tt)
171 self.assertRaises(ValueError, time.strftime, '%S\0', tt)
175 # of the time tuple (0 is valid for *all* values).
231 self._bounds_checking(lambda tup: time.strftime('', tup))
242 time.strftime(x * y + z)
253 result = time.strftime("%Y %m %d %H %M %S %w %j", (2000,)+(0,)*8)
260 tt = time.gmtime(self.t)
265 strf_output = time.strftime(format, tt)
267 time.strptime(strf_output, format)
274 self.assertRaises(TypeError, time.strptime, b'2009', "%Y")
275 self.assertRaises(TypeError, time.strptime, '2009', b'%Y')
280 time.strptime('', '%D')
284 time.strptime('19', '%Y %')
288 time.asctime(time.gmtime(self.t))
292 asc = time.asctime((bigyear, 6, 1) + (0,) * 6)
294 self.assertRaises(OverflowError, time.asctime,
296 self.assertRaises(OverflowError, time.asctime,
298 self.assertRaises(TypeError, time.asctime, 0)
299 self.assertRaises(TypeError, time.asctime, ())
300 self.assertRaises(TypeError, time.asctime, (0,) * 10)
303 self._bounds_checking(time.asctime)
306 t = time.mktime((1973, 9, 16, 1, 3, 52, 0, 0, -1))
307 self.assertEqual(time.ctime(t), 'Sun Sep 16 01:03:52 1973')
308 t = time.mktime((2000, 1, 1, 0, 0, 0, 0, 0, -1))
309 self.assertEqual(time.ctime(t), 'Sat Jan 1 00:00:00 2000')
312 testval = time.mktime((year, 1, 10) + (0,)*6)
318 self.assertEqual(time.ctime(testval)[20:], str(year))
320 @unittest.skipUnless(hasattr(time, "tzset"),
321 "time module has no attribute tzset")
326 # Epoch time of midnight Dec 25th 2002. Never DST in northern
341 # Make sure we can switch to UTC time and results are correct
345 time.tzset()
347 time.tzset()
349 time.gmtime(xmas2002), time.localtime(xmas2002)
351 self.assertEqual(time.daylight, 0)
352 self.assertEqual(time.timezone, 0)
353 self.assertEqual(time.localtime(xmas2002).tm_isdst, 0)
357 time.tzset()
358 self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002))
359 self.assertEqual(time.tzname, ('EST', 'EDT'))
360 self.assertEqual(len(time.tzname), 2)
361 self.assertEqual(time.daylight, 1)
362 self.assertEqual(time.timezone, 18000)
363 self.assertEqual(time.altzone, 14400)
364 self.assertEqual(time.localtime(xmas2002).tm_isdst, 0)
365 self.assertEqual(len(time.tzname), 2)
369 time.tzset()
370 self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002))
372 # Issue #11886: Australian Eastern Standard Time (UTC+10) is called
373 # "EST" (as Eastern Standard Time, UTC-5) instead of "AEST"
378 self.assertIn(time.tzname[0], ('AEST' 'EST'), time.tzname[0])
379 self.assertTrue(time.tzname[1] in ('AEDT', 'EDT'), str(time.tzname[1]))
380 self.assertEqual(len(time.tzname), 2)
381 self.assertEqual(time.daylight, 1)
382 self.assertEqual(time.timezone, -36000)
383 self.assertEqual(time.altzone, -39600)
384 self.assertEqual(time.localtime(xmas2002).tm_isdst, 1)
393 time.tzset()
400 for func in time.ctime, time.gmtime, time.localtime:
406 # at any time. Make sure these are at least accepted and
408 time.ctime()
409 time.ctime(None)
412 gt0 = time.gmtime()
413 gt1 = time.gmtime(None)
414 t0 = time.mktime(gt0)
415 t1 = time.mktime(gt1)
419 lt0 = time.localtime()
420 lt1 = time.localtime(None)
421 t0 = time.mktime(lt0)
422 t1 = time.mktime(lt1)
429 tt = time.localtime(t)
433 self.assertEqual(time.mktime(tt), t)
443 tt = time.gmtime(self.t)
444 tzname = time.strftime('%Z', tt)
447 time.mktime((-1, 1, 1, 0, 0, 0, -1, -1, -1))
450 self.assertEqual(time.strftime('%Z', tt), tzname)
454 times = [time.monotonic() for n in range(100)]
460 # monotonic() includes time elapsed during a sleep
461 t1 = time.monotonic()
462 time.sleep(0.5)
463 t2 = time.monotonic()
471 info = time.get_clock_info('monotonic')
476 time.perf_counter()
479 # process_time() should not include time spend during a sleep
480 start = time.process_time()
481 time.sleep(0.100)
482 stop = time.process_time()
487 info = time.get_clock_info('process_time')
492 if not hasattr(time, 'thread_time'):
494 self.fail("time.thread_time() should be available on %r"
497 self.skipTest("need time.thread_time")
499 # thread_time() should not include time spend during a sleep
500 start = time.thread_time()
501 time.sleep(0.100)
502 stop = time.thread_time()
507 info = time.get_clock_info('thread_time')
511 @unittest.skipUnless(hasattr(time, 'clock_settime'),
512 'need time.clock_settime')
514 t1 = time.monotonic()
515 realtime = time.clock_gettime(time.CLOCK_REALTIME)
518 time.clock_settime(time.CLOCK_REALTIME, realtime - 3600)
521 t2 = time.monotonic()
522 time.clock_settime(time.CLOCK_REALTIME, realtime)
531 time.localtime(time_t)
540 self.assertRaises(OSError, time.localtime, invalid_time_t)
541 self.assertRaises(OSError, time.ctime, invalid_time_t)
544 self.assertRaises(ValueError, time.localtime, float("nan"))
545 self.assertRaises(ValueError, time.ctime, float("nan"))
548 clocks = ['monotonic', 'perf_counter', 'process_time', 'time']
551 info = time.get_clock_info(name)
563 self.assertRaises(ValueError, time.get_clock_info, 'xxx')
579 time.strftime("%B", (2009,2,1,0,0,0,0,0,0))
586 return time.asctime((y,) + (0,) * 8).split()[-1]
600 if time.strftime('%Y', (1,) + (0,) * 8) == '0001':
606 return time.strftime('%Y', (y,) + (0,) * 8)
614 return time.strftime('%4Y', (y,) + (0,) * 8)
621 time.strftime('%Y', (y,) + (0,) * 8)
680 @unittest.skipUnless(time._STRUCT_TM_ITEMS == 11, "needs tm_zone support")
684 lt = time.localtime()
691 self.assertTrue(not hasattr(time, "timezone"))
693 self.assertEqual(lt.tm_gmtoff, -[time.timezone, time.altzone][lt.tm_isdst])
695 self.assertTrue(not hasattr(time, "tzname"))
697 self.assertEqual(lt.tm_zone, time.tzname[lt.tm_isdst])
702 t = time.mktime(lt); t9 = time.mktime(lt[:9])
707 new_lt = time.localtime(t); new_lt9 = time.localtime(t9)
715 @unittest.skipUnless(time._STRUCT_TM_ITEMS == 11, "needs tm_zone support")
717 t = time.strptime("UTC", "%Z")
719 t = time.strptime("+0500", "%z")
722 @unittest.skipUnless(time._STRUCT_TM_ITEMS == 11, "needs tm_zone support")
727 # Load a short time structure using pickle.
1069 self.assertTrue(hasattr(time, name), f"time.{name} is not available")
1073 self.assertFalse(hasattr(time, name), f"time.{name} is available")