Skip to content

Instantly share code, notes, and snippets.

@singe
Created July 11, 2023 17:12
Show Gist options
  • Save singe/ab827f6d8d48e2b7ab2b4b493f0a4d0e to your computer and use it in GitHub Desktop.
Save singe/ab827f6d8d48e2b7ab2b4b493f0a4d0e to your computer and use it in GitHub Desktop.
A simple “date since” tracker with milestones for Pythonista
import datetime
import ui
v = ui.load_view()
width, height = ui.get_screen_size()
v.frame = (0, 0, width, height)
v.present('sheet')
first = datetime.datetime(2023, 1, 1, 0, 0, 0, 0)
# Next 10 days
next10 = (int((datetime.datetime.now()-first).days/10)+1)*10
diff10 = first+datetime.timedelta(days=next10+1)
until10 = (diff10-datetime.datetime.now()).days
v.subviews[2].text = f"{str(next10)} days on {str(diff10.date())}\n {until10} days left"
# Next month
nextmnth = (int((datetime.datetime.now()-first).days/30.5)+1)*30.5
diffmnth = first+datetime.timedelta(days=nextmnth+1)
untilmnth = (diffmnth-datetime.datetime.now()).days
v.subviews[4].text = f"{str(int(nextmnth/(365/12)))} months ({str(nextmnth)} days) on {str(diffmnth.date())}\n {untilmnth} days left"
# Next 100 days
next = (int((datetime.datetime.now()-first).days/100)+1)*100
diff = first+datetime.timedelta(days=next+1)
until = (diff-datetime.datetime.now()).days
v.subviews[5].text = f"{str(next)} days on {str(diff.date())}\n {until} days left"
# Next Year
nextyr = (int((datetime.datetime.now()-first).days/365)+1)*365
diffyr = first+datetime.timedelta(days=nextyr+1)
untilyr = (diffyr-datetime.datetime.now()).days
v.subviews[6].text = f"{str(nextyr/365)} years ({str(nextyr)} days) on {str(diffyr.date())}\n {untilyr} days left"
while True:
now = datetime.datetime.now()
v.subviews[0].text = str(now - first).replace(', ', '\n')
if not v.on_screen:
v.close()
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment