On 26/11/07 7:31, Donald Hall wrote:
Can anyone explain this? Looks like a serious bug to me (note
differing results for 18, 20, and 100 years in the future):
Test script
---------------------------------------------------------------------------
set __today to (current date)
[...]
set newDate to __today + 17 * 365.25 * days
log newDate
set newDate to __today + 18 * 365.25 * days
log newDate
[...]
-------------------------------------------------
End of test script
Leopard (10.5.0) result:
--------------------------------------------------
tell current application
current date
date "Sunday, November 25, 2007 11:17:29 PM"
[...]
(*Monday, November 25, 2024 5:17:29 AM*)
(*Friday, September 18, 2009 12:46:20 AM*)
[...]
end tell
Tiger result:
---------------------------------------------------
tell current application
current date
date "Sunday, November 25, 2007 11:24:21 PM"
[...]
(*Monday, November 25, 2024 5:24:21 AM*)
(*Tuesday, November 25, 2025 11:24:21 AM*)
[...]
end tell
Looks like to be related to some spurious coercion occuring when the
time offset (in seconds) exceeds the largest integer that can be
expressed in AppleScript.
Let's try this one:
set CD to current date
log CD
-- Note: 536870909 seconds is a bit more than 17 years.
repeat with i from 0 to 4
log "---- " & i & " ----"
log 536870909 + i
log CD + (536870909 + i) -- [*]
log (CD + (536870909 + i)) - CD
end repeat
As soon as i reaches 3, (536870909 + i) is converted into a real, and
those strange results are then issued from line [*].
Note that the substraction of dates doesn't seem to be affected, as it
may return results bigger than the largest integer (as of line [+]):
set CD to current date
log CD
repeat with i from 0 to 4
log "---- " & i & " ----"
log 536870909 + i
log (CD + 536870909) + i
log ((CD + 536870909) + i) - CD -- [+]
end repeat
Such an asymetric behavior indeed smells like a bug.
(same behavior on both Intel and PPC)
On the other hand, the ASLG states:
AppleScript supports these operations with the + and - operators
on date and time difference values:
date + timeDifference
--result: date
date - date
--result: timeDifference
date - timeDifference
--result: date
where date is a date value and timeDifference is an integer value
specifying a time difference in seconds.
and I couldn't find a later release note explicitely extending the range
of timeDifference beyond integers.
Axel