File: clock.py

package info (click to toggle)
democracyplayer 0.9.1-1.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 20,876 kB
  • ctags: 6,313
  • sloc: python: 36,830; cpp: 1,038; ansic: 286; xml: 257; sh: 71; makefile: 30
file content (28 lines) | stat: -rw-r--r-- 625 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Originally from BitTornado
# Written by John Hoffman
# see LICENSE.txt for license information

from time import *
import sys

_MAXFORWARD = 100
_FUDGE = 1

class RelativeTime:
    def __init__(self):
        self.time = time()
        self.offset = 0

    def get_time(self):        
        t = time() + self.offset
        if t < self.time or t > self.time + _MAXFORWARD:
            self.time += _FUDGE
            self.offset += self.time - t
            return self.time
        self.time = t
        return t

if sys.platform != 'win32':
    _RTIME = RelativeTime()
    def clock():
        return _RTIME.get_time()