On Feb 5, 2010, at 7:00 AM, Mark J. Reed wrote:
On Fri, Feb 5, 2010 at 6:43 AM, Nigel Garvey <email@hidden> wrote:
Obviously we all had to make our own decisions about what to do if
either of the input dates was a Saturday or a Sunday. I posted the
various script results to help Bert and for the interest of the other
contributors. Sorry if I seemed to imply any criticism.
Absolutely not! I'm sorry if my post came off as defensive; I didn't take your post as critical. I was just trying to provide a standard against which to compare the results you compiled.
Yes. I noticed the upward rounding myself, but since Bert's script made
no attempt to convert 'days' as 24-hour periods to days as calendar
entities, I didn't see the point of it and decided to ignore it.
FWIW, looking around at the various algorithms on the net and the NETWORKDAYS function in Excel (which I can't help but read as "network days" instead of "net workdays"), inclusive counting is the norm.
From a workday to itself is one day, not zero.
Also, the problem is usually cast as counting the number of business days between two dates (inclusive of those dates), which answers the question of what to do when starting or ending on a weekend. Simply start counting with the first business day *on or after* the first date, and stop counting with the last business day *on or before* the last date. My list of manually-counted answers used that method, and so is more correct than the answers produced by my coded solution.
-- Mark J. Reed <email@hidden>
In view of these enlightening discussions, I changed the script a bit. I do not know how much sense it makes, but apparently it will now conform to a standard. So, if current date is either a Saturday or Sunday, it will be moved to Monday. It doesn't make much sense to me, but at the same time it does ???
So here is the new script:
<script>
tell application "Finder" set l to contents of item 1 of (get selection) set M to (get modification date of l) end tell set D to ((current date)) set AGE_INFO to (D - M) div (days)
on correct_AGE_INFO(AGE_INFO, D, M)
set dwi to weekday of (M) as integer set dwf to weekday of D as integer if (dwf mod 6 = 1) then set {AGE_INFO, dwf} to {AGE_INFO + 2 - (dwf mod 7), 2} set ewend to 0 if (dwf - dwi) < 0 or (dwf - dwi) = 6 then if (dwi mod 6 = 1) then set ewend to 0.5 else set ewend to 1 end if return (AGE_INFO - 2 * (AGE_INFO div 7) - 2 * ewend) div 1
end correct_AGE_INFO |