[egenix-users] Apparent bug in RelativeDateDiff() routine
Bob Gibson
bgibson at us.ibm.com
Wed Dec 8 09:56:56 CET 2004
Am I missing something? It seems that the RelativeDateDiff() routine
ignores the actual number of days in the current month when calculating the
difference. It seems to use a fixed number of days (30) for each month.
Here is a script that supports this theory.
----------------------------------------------------------------------
from mx.DateTime import *
# Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov
actual = [ 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29 ]
stop = Date( 2000, 12, 1 )
finish = stop.strftime( '%m/%d/%Y' )
for mon in range( 11, 0, -1 ) :
start = Date( 2000, mon, 2 )
begin = start.strftime( '%m/%d/%Y' )
delta = RelativeDateDiff( stop, start )
correct = actual.pop()
print "%s - %s = %2d months, and %d days [%d]" % ( finish, begin,
delta.months, delta.days, correct )
----------------------------------------------------------------------
The output of this script is as follows:
----------------------------------------------------------------------
12/01/2000 - 11/02/2000 = 0 months, and 29 days [29]
12/01/2000 - 10/02/2000 = 1 months, and 29 days [30]
12/01/2000 - 09/02/2000 = 2 months, and 29 days [29]
12/01/2000 - 08/02/2000 = 3 months, and 29 days [30]
12/01/2000 - 07/02/2000 = 4 months, and 29 days [30]
12/01/2000 - 06/02/2000 = 5 months, and 29 days [29]
12/01/2000 - 05/02/2000 = 6 months, and 29 days [30]
12/01/2000 - 04/02/2000 = 7 months, and 29 days [29]
12/01/2000 - 03/02/2000 = 8 months, and 29 days [30]
12/01/2000 - 02/02/2000 = 9 months, and 29 days [28]
12/01/2000 - 01/02/2000 = 10 months, and 29 days [30]
----------------------------------------------------------------------
The value in brackets '[]' is the correct number of days that should be
returned by RelativeDateDiff(), based upon the actual number of days in the
specified month.
For example, since 2000 was a leap year, there were 29 days in Feb, 2000.
So the number of days from Feb 2, 2000 until the 1st of Mar, should be
calculated as follows:
29 - 2 + 1 = 28
(# of days in current month) - (current day of current month ) + (# of
days into target day in next month)
Thanks
Bob
Ps 37:16 It is better to be godly and have little than to be evil and
possess much.-------------- next part --------------
An HTML attachment was scrubbed...
URL: /mailman-archives/egenix-users/attachments/20041208/3f39c930/attachment-0139.htm
More information about the egenix-users
mailing list