Skip to content

Instantly share code, notes, and snippets.

@seckcoder
Created November 2, 2019 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seckcoder/41ddea0c0666e144429157f43e3a8b20 to your computer and use it in GitHub Desktop.
Save seckcoder/41ddea0c0666e144429157f43e3a8b20 to your computer and use it in GitHub Desktop.
schengen_calculator.py
"""
Simple calculator to calculate the remaining number of days that I can stay in the schengen zone
"""
from datetime import datetime, timedelta
dates = [
"2019-06-28", "2019-07-27",
"2019-09-02", "2019-10-05",
"2019-11-08", "2019-11-25",
"2019-12-08", "2019-12-08",
"2019-12-19", "2019-12-30"
]
def to_dt(s):
return datetime.strptime(s, "%Y-%m-%d")
def main():
for i in range(0, len(dates), 2):
days = 0
assert (to_dt(dates[i]) <= to_dt(dates[i+1]))
for j in range(0, i+1, 2):
dt_i1 = to_dt(dates[i])
dt_j2 = to_dt(dates[j+1])
if dt_i1 - timedelta(days=179) <= dt_j2:
days += (dt_j2 - max(to_dt(dates[i+1]) - timedelta(days=179), to_dt(dates[j]))).days + 1
prefix = "until %s," % dates[i+1]
if days <= 90:
print "%s you have stayed for %s(days) in the Schengen Area. %s days left" % (prefix, days, 90-days)
else:
print "%s you have exceeded the allowed limit. %s days in the Schengen area" % (prefix, days)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment