"""
A class that accepts (will accept) various time specifications and returns
the number of seconds
"""

class TimeParser:
	
	def __init__(self, timestr):
		self._parseTime(timestr)
	
	def getSeconds(self):
		return self.seconds
	
	def feed(self, timestr):
		self._parseTime(timestr)
	
	def _parseTime(self, timestr):
		hours, minutes, seconds = 0, 0, 0
		parts = timestr.split(':')
		if len(parts)==3:
			self.seconds = int(parts[0])*3600+int(parts[1])*60+int(parts[2])
		elif len(parts)==2:
			self.seconds = int(parts[0])*60+int(parts[1])
		elif len(parts)==1:
			self.seconds = int(parts[0])
		else:
			raise ValueError, "Invalid time specification %s"%timestr
