Skip to content

Instantly share code, notes, and snippets.

@oscar-c
Last active April 18, 2021 22:44
Show Gist options
  • Save oscar-c/77584b994a5c4c6d1f936e7a11d87491 to your computer and use it in GitHub Desktop.
Save oscar-c/77584b994a5c4c6d1f936e7a11d87491 to your computer and use it in GitHub Desktop.
from datetime import date, timedelta
class Day(date):
@property
def 的昨天(self):
return self + timedelta(days=-1)
@property
def 的明天(self):
return self + timedelta(days=1)
if __name__ == '__main__':
理想的今天 = Day(year=2020, month=4, day=18) # a Sunday
# case A
现实的今天 = Day(year=2020, month=4, day=16) # a Friday
# "如果昨天是明天的话就好了"
assert 理想的今天.的昨天 == 现实的今天.的明天
# =====================================
# case B
现实的今天 = Day(year=2020, month=4, day=20) # a Tuesday
# "如果昨天是明天的话就好了"
assert 现实的今天.的昨天 == 理想的今天.的明天
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment