ztime.py

Created by steveg1cmz

Created on January 16, 2024

1.01 KB

ztime emulates the time module for those platforms lacking it (eg Casio) monotonic() sleepms(ms) sleep(s)


"""Ztime module emulates Python time module.
Use it on platforms that lack a time module.
Adjust loopms to match your hardware!
(Nominal resolution of current code: ms at best)
"""
__version__="0.1"
crid="Ztime\n© 2023 SteveG1CMZ"
#customise loopms for your device...Examples
loopms=7500 #Numworks on a Chromebook
loopms=5000 #Numworks on an Android
loopms= 333 #Numworks on myscripts

brokentime=False
brokentimes="[emulating broken time]"

from math import *
try: from timemodulemissing import *
except:
  brokentime=True
  def monotonic(): #where time not defined
    return float("NaN") #precludes round to int
    
  def sleepms(ms):
    #emulate a delay in ms
    for i in range(ms*loopms):
      pass
      
  def sleep(s):
    #emulate a delay in s
    sleeptime=s*1000
    for s in range(sleeptime):
      sleepms(1)

  
def tests():

  x=monotonic()
  x=monotonic()-x
  print(x)

if __name__=="__main__" or True:
  print(crid)
  if brokentime:
    print(__name__+":",brokentimes)
  tests()
  sleep(10)
  tests()