[Zope] Date

Eric Walstad Eric@Walstads.net
Tue, 21 Nov 2000 13:33:15 -0800


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:
-----8<-----8<-----8<-----
<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)">
<br>
-----8<-----8<-----8<-----

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

strMonthName=ZopeDateTime.Month()

dicDaysPerMonth =
{'January':31,'February':intDaysInFebruary,'March':31,'April':30,'May':31,'J
une':30,'July':31,'August':31,'September':30,'October':31,'November':30,'Dec
ember':31}

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

i = 2

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

days = days + ZopeDateTime.day() - 1

return ZopeDateTime + days
-----8<-----8<-----8<-----

-----Original Message-----
From: Eric Walstad [mailto:Eric@Walstads.net]
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:tom.deprez@uz.kuleuven.ac.be]
Sent: Tuesday, November 21, 2000 9:43 AM
To: Eric@Walstads.net
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.

Tom.

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,
>Eric
>
>-----Original Message-----
>From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Tom
>Deprez
>Sent: Tuesday, November 21, 2000 8:38 AM
>To: zope@zope.org
>Subject: [Zope] Date
>
>
>Does someone knows how to calculate the date after 6 months of a certain
>date?
>
>eg ZopeTime() + 6 months?
>
>Is there an easy formula for this? Or do I've to check myself for a new
>year, leap year
>
>Tom.
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>
>