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:
Emmanuel <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Fri, 23 May 2003 10:07:24 +0200
Content-Type:
text/plain
Parts/Attachments:
text/plain (37 lines)
At 12:11 PM +1300 22/05/03, Joe Barwell wrote:
><shrug>  Oh well, I imagine Richard Morton won't mind if I post his
>handy summary here: <http://www.macadillo.com/ATW/shortdate.html>,
>which includes a brief explanation/acknowledgement of its name.

On Richard's site, the examples are mostly to retrieve the current month.

For the current month, the code may be shorter. (I've tagged "OT" because this remark is not operationally relevant, just fun.)

on CurrentMonthIndex()
        1 + (date "1" - date "1/1") div (28 * days)
end CurrentMonthIndex

[1] [2]

Still on that topic, I suggest that when we publish that kind of code we favor readability and rememberability rather than wit and compactness (let alone speed). [3]

Namely, I suggest that we use "days" instead of the constants, e.g. "28 * days". I hope this might help scripters use it without having to maintain some URL or some "monthindex()" handler.

-------------------------- tested for WWII D-Day and my birthday
on MonthIndexFromDate(theDate)
        copy theDate to theOtherDate
        set month of theOtherDate to january
        1 + (theDate - theOtherDate) div (28 * days)
end MonthIndexFromDate
-----------------------------------

Of course that handler won't comply to the thorough specifications that Nigel has introduced, but it surely fits most purposes.

Emmanuel



[1] You should add more parentheses and & "" to make it stable thru compilation.
[2] Note that "div" has precedence over "+", saving one pair of parentheses.
[3] Being largely guilty for the obfuscation I apologize here.

ATOM RSS1 RSS2