Here you go Tom.  I think this is what you are looking for.
There's probably a more streamlined way to implement it, but this seems to
work nicely.
Sorry for the VB-style variable names (grin)

Hope you find it useful.  -Eric.

Here's the (ONLY) DTML used to test the functions:
<dtml-call expr="REQUEST.set('d', ZopeTime('1999/11/21'))">
Here's the result of dateInNMonths on November 21, 1999 + 6 months:<br>
<dtml-var expr="dateInNMonths(this(),d, 6)">

I implemented it using two "Python Methods" as follows:
ID: daysPerMonth
Parameters: ZopeDateTime         <-- Pass in a Zope Date Time object
if ZopeDateTime.isLeapYear():
    intDaysInFebruary = 29
    intDaysInFebruary = 28


dicDaysPerMonth =

return dicDaysPerMonth.get(strMonthName, 0)
ID: dateInNMonths
Parameters: self, ZopeDateTime, Months
days = self.daysPerMonth(ZopeDateTime) - + 1

i = 2

while i < Months:
    nextDate = ZopeDateTime + days
    days = days + self.daysPerMonth(nextDate)
    i = i + 1

days = days + - 1

return ZopeDateTime + days

-----Original Message-----
From: Eric Walstad [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 21, 2000 10:19 AM
To: Tom Deprez
Subject: RE: [Zope] Date

Hi Again Tom,
OK, This is an interesting one that I may need later on.  I'll work on it
and get back to you...

-----Original Message-----
From: Tom Deprez [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 21, 2000 9:43 AM
Subject: RE: [Zope] Date

Thanks Eric,

Unfortunately, although I only need to know the month and the year, I need
to know the exact month. In certain circumstances the method below will
give me a wrong month.


At 09:29 21/11/2000 -0800, Eric Walstad wrote:
>Hi Tom,
>I have a Python Method (or whatever they're called now) that uses the
>following line
>d = self.ZopeTime() + days
>So, you could do something like:
>d = self.ZopeTime() + (days * 30 * 6)
>However, not all months are 30 days so this isn't totally accurate.  But,
>maybe it's good enough for your needs.
>Hope it helps,
>-----Original Message-----
>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Tom
>Sent: Tuesday, November 21, 2000 8:38 AM
>Subject: [Zope] Date
>Does someone knows how to calculate the date after 6 months of a certain
>eg ZopeTime() + 6 months?
>Is there an easy formula for this? Or do I've to check myself for a new
>year, leap year
>Zope maillist  -  [EMAIL PROTECTED]
>**   No cross posts or HTML encoding!  **
>(Related lists -
> )

Zope maillist  -  [EMAIL PROTECTED]
**   No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to