def largest_running_time(self, category): from timeclock import get_timestamp if not category in self.categories: raise Exception("{0} is not a known category".format(category)) largest = None times = self.categories[category] idx = 0 len(times) num_times = len(times) while idx < num_times: start = times[idx] idx += 1 if idx >= num_times: stop = get_timestamp() else: stop = times[idx] idx += 1 thetime = stop - start if largest is None: largest = (thetime, start, stop) else: if thetime > largest[0]: largest = (thetime, start, stop) return largest
def punch(self, category, timestamp=None): from timeclock import get_timestamp if not timestamp: _timestamp = get_timestamp() else: _timestamp = timestamp with open(self.clock_filename, "a") as outfile: outfile.write("{0}\t{1}\n".format(category, _timestamp))
def get_total_time(category): from timeclock import get_timestamp punches = self.categories[category] elapsed_time = 0 length = len(punches) if length % 2 != 0: length -= 1 idx = 0 while idx < length: start = punches[idx] stop = punches[idx + 1] elapsed_time += stop - start idx += 2 if len(punches) % 2 != 0: elapsed_time += get_timestamp() - punches[-1] return elapsed_time
def date2unix(): import time from timeclock import get_timestamp from datetime import datetime as DT # Get current time data currunixtime = get_timestamp() currdatetime = DT.fromtimestamp(currunixtime).strftime('%Y%m%d %H:%M') secoffset = DT.fromtimestamp(currunixtime).strftime('%S') currunixtime -= int(secoffset) print("Current Unix Time: %d" % currunixtime) print("Current Date Time: %s" % currdatetime) # Run script unixtime = run_command("date2unix %s" % currdatetime) unixtime = unixtime.strip() unixtime = int(unixtime) # Compare retval = (unixtime == currunixtime) print("Calculated Unix Time: %d" % unixtime) return retval