This post is a follow-up from ‘Easy Way to Get the Difference of Two Times in Python’, seen here. If confused, please read that first, then come back to this.
So, continuing from where we left off, lets say we want to get the number of days till christmas. For that, we’d do the following.
#! /usr/bin/python3
import arrow
class CustomArrow(arrow.Arrow):
def days_till_xmas(self):
xmas = arrow.Arrow(self.year, 12, 25)
if self > xmas:
xmas = xmas.replace(years=1)
return (xmas - self).days
factory = arrow.ArrowFactory(CustomArrow)
mytime = factory.now()
print(mytime.days_till_xmas())
And boom, that’s it!