Mercurial > repo
comparison bin/beat @ 11942:4642242a7945 draft
<wib_jonas> fetch bin/beat https://hack.esolangs.org/get/bin/beat
author | HackEso <hackeso@esolangs.org> |
---|---|
date | Tue, 17 Sep 2019 13:32:58 +0000 |
parents | e48305a84ee8 |
children |
comparison
equal
deleted
inserted
replaced
11941:e48305a84ee8 | 11942:4642242a7945 |
---|---|
1 #!/usr/bin/python3 | 1 #!/usr/bin/python3 |
2 # beat - print current time in Swatch Internet Time format. | 2 # beat - print current time in Swatch Internet Time format. |
3 # blame fizzie | 3 # blame fizzie |
4 import math,sys,getopt,time | 4 import math,sys,getopt,time |
5 prec = 0 | 5 prec = 0 |
6 opts,args = getopt.getopt(sys.argv[1:], "hpP:") | 6 atime = None |
7 opts,args = getopt.getopt(sys.argv[1:], "d:hpP:") | |
7 for opt,oarg in opts: | 8 for opt,oarg in opts: |
8 if "-p" == opt: prec = 2 | 9 if "-d" == opt: |
10 if "@" == oarg[0]: | |
11 atime = float(oarg[1:]) | |
12 else: | |
13 raise RuntimeError("unknown date format") | |
14 elif "-p" == opt: prec = 2 | |
9 elif "-P" == opt: prec = int(oarg) | 15 elif "-P" == opt: prec = int(oarg) |
10 elif "-h" == opt: print("Usage: beat [-p]\nPrint current time in Swatch Internet Time format."); sys.exit(2) | 16 elif "-h" == opt: |
17 print("Usage: beat [-p]\nPrint current time in Swatch Internet Time format.\n") | |
18 sys.exit(2) | |
11 else: raise AssertionError() | 19 else: raise AssertionError() |
12 if args: | 20 if args: |
13 raise RuntimeError("too many command-line arguments") | 21 raise RuntimeError("too many command-line arguments") |
14 b = math.floor(((time.time()+3600) % 86400) / 86.4 * 10**prec) | 22 if atime is None: |
23 atime = time.time() | |
24 b = math.floor(((atime + 3600) % 86400) / 86.4 * 10**prec) | |
15 o = "%0*d" % (prec, b) | 25 o = "%0*d" % (prec, b) |
16 if 0 < prec: o = o[0:-prec] + "." + o[-prec:] | 26 if 0 < prec: o = o[0:-prec] + "." + o[-prec:] |
17 print(o) | 27 print(o) |
18 #END | 28 #END |