ztime.py

Created by steveg1cmz

Created on September 08, 2024

1.01 KB

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

Try loopms=125 on a Casio CG50.


"""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()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.