#!/usr/bin/env python3 """ Calculates the fraction of a year that the period from today's date to the given date constitutes, optionally multiplies it with a value, and prints the result. E.g. useful to see if a second-hand whole-year gym membership is actually discounted. """ import sys import datetime datestr = sys.argv[1] value = 1 if len(sys.argv) >= 3: value = float(sys.argv[2]) d0 = datetime.date.today() d1 = datetime.datetime.strptime(datestr, "%Y-%m-%d").date() days_in_year = datetime.date(2, 1, 1) - datetime.date(1, 1, 1) print(value * ((d1 - d0) / days_in_year))