[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUtrition-commits] /srv/bzr/gnutrition/trunk r12: Added calculation to
From: |
Thomas Sinclair |
Subject: |
[GNUtrition-commits] /srv/bzr/gnutrition/trunk r12: Added calculation to account for Feb 29 (needed by nutrient calculation for span |
Date: |
Sun, 16 Sep 2012 20:15:56 -0400 |
User-agent: |
Bazaar (2.5.0) |
------------------------------------------------------------
revno: 12
committer: Thomas Sinclair <address@hidden>
branch nick: trunk
timestamp: Sun 2012-09-16 20:15:56 -0400
message:
Added calculation to account for Feb 29 (needed by nutrient calculation for
span
of more than one day when the span would include Feb 29
modified:
src/database.py
=== modified file 'src/database.py'
--- a/src/database.py 2012-09-16 23:02:12 +0000
+++ b/src/database.py 2012-09-17 00:15:56 +0000
@@ -29,11 +29,25 @@
"""Return todays date as yyyy-mm-dd"""
return str(dbms.DateFromTicks(ticks()))
+def leap_year(year):
+ if year % 400 == 0:
+ return True
+ if year % 100 == 0:
+ return False
+ if year % 4 == 0:
+ return True
+ return False
+
def to_days(datestr):
# J F M A M J J A S O N D
months = [31,28,31,20,31,30,31,31,30,31,30,31]
ymd = datestr.split('-')
- days = (int(ymd[0]) - 1900) * 365;
+ year = int(ymd[0])
+ # We only need to know if we are spanning Feb 29
+ # BTW: the next year is 2016
+ if leap_year(year):
+ months[1] = 29
+ days = (year - 1900) * 365;
days = days + months[int(ymd[1])] + int(ymd[2])
return days
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUtrition-commits] /srv/bzr/gnutrition/trunk r12: Added calculation to account for Feb 29 (needed by nutrient calculation for span,
Thomas Sinclair <=