Spent Friday investigating some freakish code problems. This one just blew my mind....
When assigning numbers to a data type what do you expect to happen when you assign a number to big to fit the assigned data type? Right, an overflow error.
Well explain this then....
Ok, yes I know, you can solve it by using "difference# = notesDateTime.TimeDifferenceDouble( notesDateTime )" method which will return a double. I just can't get my head around the fact that it didn't return an error when it overflowed on 2,147,483,647 and instead continued up from it's negative boundary (-2,147,483,648).
Or is this normal behavior for a Long data type?? I just hate it when I can't logically explain something...
Code I used to test the effect:
Sub Click(Source As Button)
Dim todayD As New NotesDateTime(Today)
Dim AlteredDate As New NotesDateTime(Today)
Set todayD = New NotesDateTime(Today)
todayD.Localtime = todayD.Dateonly + " 00:00:00"
Set AlteredDate = New NotesDateTime(Today)
AlteredDate.Localtime = AlteredDate.Dateonly + " 00:00:00"
For x = 24850 To 24860
Set AlteredDate = New NotesDateTime(Today)
Call AlteredDate.AdjustDay(-x)
If TodayD.Timedifference(AlteredDate)<0 Then
'EXPECTED OVERFLOW ERROR AT 24857 NOT HAPPENING
Dim todayD As New NotesDateTime(Today)
Dim AlteredDate As New NotesDateTime(Today)
Set todayD = New NotesDateTime(Today)
todayD.Localtime = todayD.Dateonly + " 00:00:00"
Set AlteredDate = New NotesDateTime(Today)
AlteredDate.Localtime = AlteredDate.Dateonly + " 00:00:00"
For x = 24850 To 24860
Set AlteredDate = New NotesDateTime(Today)
Call AlteredDate.AdjustDay(-x)
If TodayD.Timedifference(AlteredDate)<0 Then
'EXPECTED OVERFLOW ERROR AT 24857 NOT HAPPENING
End If
Print "TimeDifference between: " + TodayD.DateOnly + " and " +_
AlteredDate.DateOnly + " = " + Cstr(TodayD.Timedifference(AlteredDate)) +_
" ---- Days: " + Cstr(x)
Next
Print "TimeDifference between: " + TodayD.DateOnly + " and " +_
AlteredDate.DateOnly + " = " + Cstr(TodayD.Timedifference(AlteredDate)) +_
" ---- Days: " + Cstr(x)
Next
End Sub
Update: I got this answer back through Twitter: "@FemkeGoedhart normal behavior for int/long. See http://en.m.wikipedia.org/wiki/Integer_overflow" Thanks @Thimo! It explains it, although the logic of Lotusscript returning an error on overflow of Integers but not on Longs still eludes me....
