BlinkenArea - GitList
Repositories
Blog
Wiki
stage_director
Code
Commits
Branches
Tags
Search
Tree:
ab7eb54
Branches
Tags
master
stage_director
time_fmt.py
reading playlist
Stefan Schuermans
commited
ab7eb54
at 2013-11-14 22:23:33
time_fmt.py
Blame
History
Raw
#! /usr/bin/env python def sec2str(sec): sign = "" if sec < 0: sign = "-"; sec = -sec; sec1 = int(sec) sec100 = round((sec - sec1) * 100) minu = sec1 // 60 sec1 = sec1 % 60 hour = minu // 60 minu = minu % 60 return "%s%u:%02u:%02u.%02u" % (sign, hour, minu, sec1, sec100) def str2sec(str): total = 0 section = 0 sign = 1 decimal = 1 for c in str: if c == ":": total = (total + sign * section) * 60 section = 0 sign = 1 decimal = 1 elif c == "-": sign = -sign elif c == ".": decimal = 0.1 elif c >= "0" and c <= "9": if decimal < 1: section = section + int(c) * decimal decimal = decimal * 0.1 else: section = section * 10 + int(c) total = total + sign * section return total