wie verwenden

./timespan.py 930 2340

930 - 2340

14:10:00

das script: timespan.py

     #!/home/joachim/.nix-profile/bin/python
     from datetime import timedelta
     import time
     import sys
     
     def compute_difference(beginstr, endstr):
       if len(beginstr) == 3:
               start_hour=beginstr[0:1]
               start_minute=beginstr[1:3]
       elif len(beginstr) == 4:
               start_hour=beginstr[0:2]
               start_minute=beginstr[2:4]
       else:
               print "fatal error: " + beginstr + " can't be parsed"
               exit(1)
       if len(endstr) == 3:
               end_hour=endstr[0:1]
               end_minute=endstr[1:3]
       elif len(endstr) == 4:
               end_hour=endstr[0:2]
               end_minute=endstr[2:4]
       else:
               print "fatal error: " + endstr + " can't be parsed"
               exit(1)
     
       print start_hour + "" + start_minute + " - " +  end_hour + "" + end_minute
       start = timedelta(weeks=40, days=84, hours=int(start_hour), minutes=int(start_minute), seconds=600)  # adds up to 365 days
       end =   timedelta(weeks=40, days=84, hours=int(end_hour), minutes=int(end_minute), seconds=600)  # adds up to 365 days
       print end - start
     
     
     if len(sys.argv) != 3:
       print "Usage: " + sys.argv[0] + " 930 1334"
       exit(1)
     else:
       if not ((len(sys.argv[1]) == 3) or (len(sys.argv[1]) == 4)):
               print "Usage: " + sys.argv[0] + " 930 1334"
               exit(1)
       else:
               compute_difference(sys.argv[1], sys.argv[2]);
Powered by MediaWiki