Mathias Panzenböck avatar Mathias Panzenböck committed 602631c

fix formatting negative spans and more nice quota printing

Comments (0)

Files changed (1)

 def stripfspan(span):
 	buf = []
 	seconds = span.seconds + span.days * 24 * 60 * 60
+	if seconds < 0:
+		negative = True
+		seconds = -seconds
+	else:
+		negative = False
 	if seconds:
-		if abs(seconds) >= 60:
+		if seconds >= 60:
 			minutes = seconds // 60
 			seconds -= minutes * 60
-			if abs(minutes) >= 60:
+			if minutes >= 60:
 				hours = minutes // 60
 				minutes -= hours * 60
 			else:
 		if seconds:
 			buf.append('%ds' % seconds)
 	if buf:
-		return ' '.join(buf)
+		s = ' '.join(buf)
+		if negative:
+			s = '-'+s
+		return s
 	else:
 		return '0s'
 
 	seconds = span.seconds + span.days * 24 * 60 * 60
 	minutes = 0
 	hours = 0
+	if seconds < 0:
+		negative = True
+		seconds = -seconds
+	else:
+		negative = False
 	if seconds:
-		if abs(seconds) >= 60:
+		if seconds >= 60:
 			minutes = seconds // 60
 			seconds -= minutes * 60
-			if abs(minutes) >= 60:
+			if minutes >= 60:
 				hours = minutes // 60
 				minutes -= hours * 60
 			if hours:
 	if not (hours or minutes or seconds):
 		return '          0s'
 	else:
-		return ' '.join(buf)
+		s = ' '.join(buf)
+		if negative:
+			s = '-'+s
+		return s
 
 class Quota(object):
 	def __init__(self,start,end,hours):
 	
 	def printQuota(self):
 		workdays, quota, worked = self.quota()
-		sys.stdout.write(
-			'%d workdays, %s quota, %s worked, %s missing\n' %
-			(workdays,
-			 stripfspan(quota),
-			 stripfspan(worked),
-			 stripfspan(quota - worked)))
+		missing = quota - worked
+		if missing < timedelta(0):
+			sys.stdout.write(
+				'%d workdays, %s quota, %s worked, %s credit :)\n' %
+				(workdays,
+				 stripfspan(quota),
+				 stripfspan(worked),
+				 stripfspan(-missing)))
+		elif quota == worked:
+			sys.stdout.write(
+				'%d workdays, %s quota, %s worked, exactly balanced\n' %
+				(workdays,
+				 stripfspan(quota),
+				 stripfspan(worked)))
+		else:
+			sys.stdout.write(
+				'%d workdays, %s quota, %s worked, %s missing :(\n' %
+				(workdays,
+				 stripfspan(quota),
+				 stripfspan(worked),
+				 stripfspan(missing)))
 	
 	def configDir(self):
 		try:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.