From 2180fa02cb05d428b3fdce5a82987deceba67157 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sun, 24 Feb 2008 00:58:33 +0000 Subject: [PATCH] 2008-02-23 Douglas S. Blank * src/gen/lib/date.py (Date.get_stop_date): added new method Date.to_calendar; dates return None if error svn: r10102 --- ChangeLog | 4 ++++ src/gen/lib/date.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d85a0c597..54e6a10ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-02-23 Douglas S. Blank + * src/gen/lib/date.py (Date.get_stop_date): + added new method Date.to_calendar; dates return None if error + 2008-02-23 Jerome Rapinat * configure.in : allow Slovenian support diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index f59e611f9..5ab3954e1 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -322,7 +322,7 @@ class Date: diff += 1 eDate = eDate + (0, 0, diff) if diff == 60: - return (0, 0, 0) + return None return (years, months, days - diff) elif eDate > date2: diff = 0 @@ -330,7 +330,7 @@ class Date: diff -= 1 eDate = eDate - (0, 0, abs(diff)) if diff == -60: - return (0, 0, 0) + return None return (years, months, days + diff) else: return (years, months, days) @@ -1003,3 +1003,13 @@ class Date: else: raise AttributeError("invalid modifier: '%s'" % modifier) + def to_calendar(self, calendar_name): + """ + Return a new Date object in the calendar calendar_name. + >>> Date("Jan 1 1591").to_calendar("julian") + 1590-12-22 (Julian) + """ + cal = self.lookup_calendar(calendar_name) + retval = Date(self) + retval.convert_calendar(cal) + return retval