[ic] time tag with adjust in February bug?

Peter peter at pajamian.dhs.org
Mon Apr 1 11:35:04 UTC 2013


On 04/01/2013 10:30 PM, Gert van der Spoel wrote:
> Let me take the bait, april's fool or not ... The 1 minute difference, not
> sure ... But for the other ... Same issue you'd see if you take the date of
> 31st May 2013 and do -1 month 1 day  ...
>
> What do you expect? 1 month down = April ... April has 30 days .. So 1 month
> 1 day you'd say is: 29 April ... Well it does not work like that I think,
> because I tis fed to mktime 31-1 = 30   4-1=3 ... So that makes April 30th
> .. And for the above Feb 30 = March 2 because it compensates the days.

Actually this is exactly what it's doing, you've hit the nail on the head.

> If you take 1st of June and do that -1 month -1 day it is fed to mktime as
> 1-1=0   5-1=4     mktime then apparently says: Oh I get 0 that means I need
> to take the last day of the previous month (30) and drop the month another
> nodge (3) ... So 30th of April and all looks good.

Which is probably what you would want in this particular case.

> So the bottom line I'd say is: the time_adjust function is faulty as it does
> not properly feed information to mktime

Being that I wrote the code I'm a bit partial to calling it faulty.  It 
does exactly what you tell it to do, and the result of subtracting one 
month and one day is open to interpretation as to what the desired 
outcome is.  At the end of the day this is certainly not an "incorrect" 
outcome, it is just probably not the exact one that you would expect.

> .. As Mike says: " And you can't do
> addition and subtraction by combining terms"  ... The code seems to say: Yes
> you can ... But the reality is: with this code you cannot.

The code I wrote does introduce the concept of "months" into the 
equation, due to the fact that different months have different numbers 
of days this is not an exact science.  If you want to use months in your 
equation you get the result you get, if you don't then you won't have 
this problem, just like you would not have had it with the older code 
that did not recognize months.

That said, if anyone has a suggestion as to how to improve the function 
I am certainly open to it.


Peter



More information about the interchange-users mailing list