# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Topic: FBTime
#

from pyfbsdk import FBSystem, FBTime, FBSleep, FBMessageBox

# Get a timestamp before the sleep.
lTs1 = FBSystem().SystemTime

# Do sleep for a few milliseconds.
lSleepTimeMS = 1234
FBSleep( lSleepTimeMS )

# Get a second timestamp after the sleep.
lTs2 = FBSystem().SystemTime
lTdiff = lTs2 - lTs1

# Now display the actual sleep time.
FBMessageBox( "Actual sleep time",
              "Sleep time requested: %.3f seconds\nActual sleep time   : %.3f seconds" %
              (( lSleepTimeMS / 1000.0 ),
              (lTdiff.GetMilliSeconds() / 1000.0)),
              "OK",
              None,
              None )

# There are some predefined time unit: Infinity, MinusInfinity, Zero, OneSecond, OneMinute, OneHour.  
lTs1 = FBTime.OneSecond
lTs2 = FBTime.OneMinute
lTdiff = lTs2 - lTs1

FBMessageBox( "Time Math",
              "one minutues - one second = %.0f seconds" %
              (lTdiff.GetMilliSeconds() / 1000.0),
              "OK",
              None,
              None )
# Cleanup.
del( lTs1, lTs2, lTdiff, lSleepTimeMS, FBSystem, FBTime, FBSleep, FBMessageBox )