MACSCRPT Archives

May 2003

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Nigel Garvey <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Sun, 25 May 2003 16:59:43 +0100
Content-Type:
text/plain
Parts/Attachments:
text/plain (94 lines)
Joe Barwell wrote on Sat, 24 May 2003 23:27:55 +1300:

>On Sat, 24 May 2003, Nigel Garvey
><[log in to unmask]> wrote:
>
>>That *is* a "monthindex()" handler! ;-)
>
>Seemed like one to me. <non-gallic shrug>
>
>>  if theDate's year comes before 1904 then
>>    copy theDate to theDate
>
>American vanilla seems to repeat on me.

The line makes more sense inside a "monthindex()" handler. ;-)



Emmanuel wrote on Sat, 24 May 2003 14:49:28 +0200:

>At 10:33 AM +0100 24/05/03, Nigel Garvey wrote:

>>That *is* a "monthindex()" handler! ;-)
>
>You must be kidding.
>
>Yes that *is* a "monthindex()" handler but not one that you have to copy
>from here and maintain available.
>
>What I claim is that scripters can write such a handler off the top of
>their head, while they could not for the original handler that was full of
>cryptic figures.

Yeah. Sorry, Emmanuel. Actually, I agree with your motive, but I wouldn't
say that Richard Hartman's divisor (two-and-a-half million) was
particularly difficult to remember. Anyone who was familiar enough with
French Vanilla to be able to reconstruct it from memory using '(28 *
days)' would find that '2500000' came to mind just as easily. In future,
I shall publicise that number rather than playfully enthusing over my
tricks with the cryptic original.


I must say I'm a little disappointed at the muted reaction to my
revelation of "English Fudge". Still, that's given me a little time to
refine it. ;-) As posted yesterday:

>  copy theDate to b
>  set b's month to January
>  1 - (b - 1 - theDate) div (28 * days)

It works with every date I've tested so far in the AppleScript date
range, including those that come before 1904. Because of a Mac OS
date-subtraction bug, French Vanilla crashes on dates before 1904. (I
know what you're thinking, but it's a vulnerability nonetheless.)

It turns out that the bug doesn't kick in when a later date is subtracted
from an earlier one, so English Fudge subtracts the January date from the
original instead of vice versa. Since the two dates are exactly the same
when the original date's in January, one second is subtracted from the
'January' date to ensure a later-from-earlier subtraction. (This works
even when the intermediate result is outside the official AppleScript
date range.) The result of the 'div' is then *subtracted* from the first
'1' in the line to cancel out the negatives.

More elegantly, the subtraction from the January date (or, if you prefer,
an addition to the original date) can be the amount of the divisor -
which removes the need for the '1' at the beginning of the line. The
"double negative" is then obtained by using a negative divisor:

  (b - (28 * days) - theDate) div (-28 * days)

or:

  (b - (theDate + (28 * days))) div (-28 * days)

The advantage is more apparent when using Richard's divisor, where the
whole process is either:

  copy theDate to b
  set b's month to January
  (b - 2500000 - theDate) div -2500000

or:

  copy theDate to b
  set b's month to January
  (b - (theDate + 2500000)) div -2500000

This is as brief as Richard's original optimisation, not too difficult to
remember, and - so far - bulletproof. (But in Mac OS 9, stay away from
January 1st in the 101st year of any Gregorian cycle.)

NG

ATOM RSS1 RSS2