#
# BusyB, an automated build utility.
#
# Copyright (C) 1997-2003
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
import os
class Interval:
def setParent(self, parent):
parent.setInterval(self)
def getN(self):
return self.n
def setText(self, txt):
self.txt = txt
tokens=txt.split()
n=0
while len(tokens) > 0:
n = n + self.parseTerm(tokens)
self.n = n
def parseTerm(self, tokens):
num = int(tokens.pop(0))
if len(tokens) == 0:
return num
unit = tokens.pop(0).lower()
if (unit == 'seconds') or (unit == 'seconds') or (unit == 'sec') or ( unit == 's'):
return num
elif (unit == 'minutes') or (unit == "minute"):
return num * 60
elif (unit == 'min') or ( unit == 'm'):
return num * 60
elif (unit == 'hours') or (unit == 'hours') or (unit == 'hour'):
return num * 60 * 60
elif (unit == 'hr') or ( unit == 'h'):
return num * 60 * 60
elif (unit == 'days') or (unit == 'day') or ( unit == 'd'):
return num * 60 * 60 * 24
elif (unit == 'weeks') or (unit == 'week') or ( unit == 'w'):
return num * 60 * 60 * 24 * 7
elif (unit == 'months') or (unit == 'month') or ( unit == 'mon'):
return num * 60 * 60 * 24 * 7
elif (unit == 'years') or (unit == 'year') or ( unit == 'y'):
return num * 60 * 60 * 24 * 7
else:
raise "Unknown time unit: " + unit + " in interval [" + self.txt + "]"
def __call__(self):
return self.getN()
def __str__(self):
return self.txt
|