예제 #1
0
 def getGrammarTime(self, timed):
     mytime = timedelta(0)
     try:
         (temporal, pcf, when) = pcfGrammar(timed - mytime)
     except TypeError:
         (temporal, pcf, when) = pcfGrammar(mysteryTime())
     if timed == mytime:
         return TimeGrammar(temporal, pcf, when, 0)
     return TimeGrammar(temporal, pcf, when, self.getRecord(timed))
예제 #2
0
 def addRecord(self, timed):
     try:
         (temporal, pcf, when) = pcfGrammar(timed - timedelta(0))
     except TypeError:
         (temporal, pcf, when) = pcfGrammar(mysteryTime())
     if pcf == "C" or pcf == "?":
         return
     if timed in self.timerecord[pcf]:
         return
     self.timerecord[pcf].append(timed)
예제 #3
0
 def getRecord(self, timed):
     try:
         (temporal, pcf, when) = pcfGrammar(timed - timedelta(0))
     except TypeError:
         (temporal, pcf, when) = pcfGrammar(mysteryTime())
     if pcf == "C" or pcf == "?":
         return 0
     if len(self.timerecord[pcf]) > 1:
         return self.timerecord[pcf].index(timed)+1
     else:
         return 0
예제 #4
0
def timeProtocol(cmd):
    dir = cmd[0]
    if dir == "?":
        return mysteryTime(0)
    cmd = cmd[1:]
    cmd = re.sub("[^0-9:]", "", cmd)
    try:
        l = [int(x) for x in cmd.split(":")]
    except ValueError:
        l = [0,0]
    timed = timedelta(0, l[0]*3600+l[1]*60)
    if dir == "P":
        timed = timed*-1
    return timed
예제 #5
0
def timeProtocol(cmd):
    dir = cmd[0]
    if dir == "?":
        return mysteryTime(0)
    cmd = cmd[1:]
    cmd = re.sub("[^0-9:]", "", cmd)
    try:
        l = [int(x) for x in cmd.split(":")]
    except ValueError:
        l = [0,0]
    timed = timedelta(0, l[0]*3600+l[1]*60)
    if dir == "P":
        timed = timed*-1
    return timed
예제 #6
0
def txt2delta(txt):
    sign = 1
    if txt[0] == '?':
        return mysteryTime()
    if txt[0] == '+':
        txt = txt[1:]
    elif txt[0] == '-':
        sign = -1
        txt = txt[1:]
    l = txt.split(":")
    try:
        h = int(l[0])
        m = 0
        if len(l) > 1:
            m = int(l[1])
        timed = timedelta(0, h*3600+m*60)
    except ValueError:
        timed = timedelta(0)
    except OverflowError:
        if sign < 0:
            return timedelta(min)
        else:
            return timedelta(max)
    return sign*timed