Skip to content

Instantly share code, notes, and snippets.

@jersey99
Last active February 15, 2019 02:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jersey99/f2e2d5d6e4e3bf996e787156d884ac62 to your computer and use it in GitHub Desktop.
Save jersey99/f2e2d5d6e4e3bf996e787156d884ac62 to your computer and use it in GitHub Desktop.
Get your age in seconds. And find out when you hit that integer exponent in your favorite base
#!/usr/bin/env python3
import argparse
import math
from datetime import datetime, timezone, timedelta
def get_tob_from_str(tob_str):
# Time of birth
try:
tob = datetime.strptime(tob_str, "%Y-%m-%dT%H:%M:%S%z")
except ValueError:
print('illegal format')
exit(1)
x = datetime.now(timezone.utc) - tob
print("You are currently {:,} seconds old".format(int(x.total_seconds())))
return tob
def print_fun(tob, base, exponents):
for ex in exponents:
try:
dt = tob + timedelta(seconds=base**ex)
except OverflowError:
exit()
if dt > datetime.now(timezone.utc):
print('You will be {}^{:2d} seconds old at {}'.format(base, ex, dt))
else:
print('You were {}^{:02d} seconds old at {}'.format(base, ex, dt))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Get your age in seconds. And'
' find out when you hit that integer'
' exponent in your favorite base')
parser.add_argument('-t', '--tob_str', help='1987-05-31T06:45:00+0530',
default='1987-05-31T06:45:00+0530')
parser.add_argument('-b', '--base', help='base', default=math.e)
args = parser.parse_args()
tob = get_tob_from_str(args.tob_str)
exponents = range(0, 50, 1)
if args.base in ['E', 'e']:
base = math.e
elif args.base in ['pi', 'PI', 'Pi']:
base = math.pi
elif args.base in ['tau', 'TAU', 'Tau']:
base = math.tau
else:
base = float(args.base)
if base in [1, 1.0]:
exit()
if int(base) == base:
base = int(base)
print_fun(tob, base, exponents)
@letarg0
Copy link

letarg0 commented Feb 6, 2019

try Julian Days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment