Date Comparison and Manipulation Functions?
norseman
norseman at hughes.net
Fri Aug 29 14:43:01 EDT 2008
W. eWatson wrote:
> I just tried the following code, and got an unexpected result.
>
> from pyfdate import *
> t = Time()
>
> ts = Time(2008, 8, 29,15,20,7)
> tnew = ts.plus(months=6)
> print "new date: ", tnew
>
> Result:
> new date: 2009-02-28 15:20:07
>
> I believe that should be April 1, 2009. If I use months = 1 and day =31,
> I get Sept. 30, 2008 and not Oct. 1, 2008. Is there a way to get around
> this?
>
===================
Hummmm....
The old 'ditty' to help remember:
Thirty days have September, April, June and November
All the rest have 31 except February
Which has but 28 'til Leap Year gives it 29
and:
2008 08 29 DOY = 242 366 in year
2009 03 01 DOY = 60
366-242 = 124 + 60 = 184 - 1 (we don't count today) = 183
30 + 31 + 30 + 31 + 31 + 28 + 2 (left in aug.) = 183
S O N D J F A
366+60-242-1(for today)=183
Puts us on 2009 Feb. 28
case #2: I think something is described other than as used.
08 29
01 31
-----
09 60
2008 09 01 DOY = 245
245 + 60 -1(today) = 304 which is DOY for 2008 10 30
or (depending on what the written meant)
08 31
01 00
-----
09 31
2008 09 00 DOY = 245
245 + 31 -1(today) = 274 = 2008 Sept. 30
pyfdate is using actual days per month and DOY to compute.
It's not quite the same as the 'rule of thumb' that is in general public
use - but it is accurate. Most of us would just add the months and use
the day or one close to it.
Steve
norseman at hughes.net
More information about the Python-list
mailing list