~menesis/ubuntu/maverick/gtimelog/maverick

« back to all changes in this revision

Viewing changes to difftime.py

  • Committer: Bazaar Package Importer
  • Author(s): Barry Warsaw
  • Date: 2010-09-10 10:12:03 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100910101203-r7epgzni3537hkxw
Tags: 0.4.0-0ubuntu1
New packaging for new upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
import readline
3
 
 
4
 
def parse_time(s):
5
 
    h, m = map(int, s.strip().split(':'))
6
 
    return h * 60 + m
7
 
 
8
 
def fmt_delta(mins):
9
 
    sign = mins < 0 and "-" or ""
10
 
    mins = abs(mins)
11
 
    if mins >= 60:
12
 
        h = mins / 60
13
 
        m = mins % 60
14
 
        return "%s%d min (%d hr, %d min)" % (sign, mins, h, m)
15
 
    else:
16
 
        return "%s%d min" % (sign, mins)
17
 
 
18
 
while True:
19
 
    try:
20
 
        what = raw_input("start, end> ")
21
 
    except EOFError:
22
 
        print
23
 
        break
24
 
    try:
25
 
        if ',' in what:
26
 
            t1, t2 = map(parse_time, what.split(','))
27
 
        else:
28
 
            t1, t2 = map(parse_time, what.split())
29
 
        print fmt_delta(t2 - t1)
30
 
    except ValueError:
31
 
        print eval(what)
32