Commits

Tairan Wang committed f7ff394

LifeCalculator

  • Participants
  • Parent commits ddea835

Comments (0)

Files changed (1)

File lifeleft/app/__init__.py

+#-*- coding: utf8 -*-
+
+from datetime import date
+
+class LifeCalculator():    
+    total_months = 75 * 12 # 900 months
+    
+    def __init__(self, year, month, day):
+        self.birthday = date(year, month, day)
+        self.today = date.today()
+
+    def passed(self):
+        return ((((self.today.year -1) - (self.birthday.year + 1)) * 12) 
+            + (12 - self.birthday.month + self.today.month - 1))
+
+    def left(self):
+        return self.total_months - self.passed() - 1
+
+    def current(self):
+        return self.passed() + 1