From: Simon Ruderich Date: Sat, 9 Feb 2013 20:07:25 +0000 (+0100) Subject: bin/calc: Add function to convert seconds to date. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=a0e89499b7a01724b8a2806805d8432e30e4aace;p=config%2Fdotfiles.git bin/calc: Add function to convert seconds to date. --- diff --git a/bin/calc b/bin/calc index 6a40543..c364119 100755 --- a/bin/calc +++ b/bin/calc @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2011-2012 Simon Ruderich +# Copyright (C) 2011-2013 Simon Ruderich # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,7 +16,10 @@ # along with this program. If not, see . -exec python -i -c 'from math import *; +exec python -i -c ' + +# Math functions. +from math import * def ld(x): return log(x)/log(2) @@ -24,6 +27,15 @@ def ld(x): def binom(n,k): return reduce(lambda a,b: a*(n-b)/(b+1),xrange(k),1) + +# Time/Date functions. +import time + +# Convert time in seconds since epoch to readable string. +def stime(seconds): + print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(seconds)) + + print "Welcome to the ultimate calculator."' # vim: ft=python