# HG changeset patch # User HackEso # Date 1568376826 0 # Node ID d1bee51ebc7e9cc212b3b71401aa510341932fc0 # Parent 78fee00d2bd2e5bc3388179e6582ed64c9dd7765 fetch bin/beat https://hack.esolangs.org/get/bin/beat diff -r 78fee00d2bd2 -r d1bee51ebc7e bin/beat --- a/bin/beat Fri Sep 13 11:19:12 2019 +0000 +++ b/bin/beat Fri Sep 13 12:13:46 2019 +0000 @@ -1,5 +1,19 @@ -#!/usr/bin/python3 -# beat - prints current Swatch Internet Time -import math,time -b = math.floor(((time.time()+3600) % 86400) / 86.4) -print("%03d"%(b,)) +#!python3 +# beat - print current time in Swatch Internet Time format. +# blame fizzie +import math,sys,getopt,time +prec = 0 +opts,args = getopt.getopt(sys.argv[1:], "hpP:") +print(opts) +for opt,oarg in opts: + if "-p" == opt: prec = 2 + elif "-P" == opt: prec = int(oarg) + elif "-h" == opt: print("Usage: beat [-p]\nPrint current time in Swatch Internet Time format."); sys.exit(2) + else: raise AssertionError() +if args: + raise RuntimeError("too many command-line arguments") +b = math.floor(((time.time()+3600) % 86400) / 86.4 * 10**prec) +o = "%0*d" % (prec, b) +if 0 < prec: o = o[0:-prec] + "." + o[-prec:] +print(o) +#END