view bin/beat @ 11951:f96359542199 draft

<ais523> ` printf \'#include <stdio.h>\\nint main(void) { float C = 4.0; printf("%%f", C/C++); }\' | gcc -fno-diagnostics-color -Wall -Wextra -x c /dev/stdin
author HackEso <hackeso@esolangs.org>
date Thu, 19 Sep 2019 17:56:36 +0000
parents 4642242a7945
children
line wrap: on
line source

#!/usr/bin/python3
# beat - print current time in Swatch Internet Time format.
# blame fizzie
import math,sys,getopt,time
prec = 0
atime = None
opts,args = getopt.getopt(sys.argv[1:], "d:hpP:")
for opt,oarg in opts:
	if "-d" == opt:
		if "@" == oarg[0]:
			atime = float(oarg[1:])
		else:
			raise RuntimeError("unknown date format")
	elif "-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.\n")
		sys.exit(2)
	else: raise AssertionError()
if args:
	raise RuntimeError("too many command-line arguments")
if atime is None:
	atime = time.time()
b = math.floor(((atime + 3600) % 86400) / 86.4 * 10**prec)
o = "%0*d" % (prec, b)
if 0 < prec: o = o[0:-prec] + "." + o[-prec:]
print(o)
#END