Re: Dual Purpose Applet Question
Re: Dual Purpose Applet Question
- Subject: Re: Dual Purpose Applet Question
- From: email@hidden
- Date: Wed, 6 Dec 2000 00:48:59 -0500
On Tue, 05 Dec 2000 19:26:11 +0000, From: Mr Tea <email@hidden> asked,
>
I guess I was just too timid there. Thanks for the encouragement. The
>
following works a treat...
>
>
on open fileList
>
--start single line
>
set theName to (day of (current date) as string) & " " &
>
(characters 1 thru 3 of (month of (current date) as string) as string)
>
& " " & (year of (current date) as string) & " - " &
>
time string of (current date)
>
--end single line
[...]
>
>
Now, if anyone can suggest a neater way of setting 'theName'...
I'm lazy, and use the Unix Date OSAX, to give me a compact date format.
Tanaka's Osax has a "Timestamp" call that gives you YYMMDDHHMMSS, useful for
sorting, but hard for people to read. But if you want to do it yourself, the
first thing to do would be to only get "current date" once. Not only is this
more efficient, but may prevent a malformed date if the clock or time zone gets
reset or rolls over midnight between calls to "current date." That is, if
midnight of the new year comes in the middle of the execution of theName's
expression's evaluation, you might get,
set theName to
(day of (current date) as string) <-- at 31 Dec 2000 23:59:59.9
& " " &
(characters 1 thru 3 of
(month of (current date) as string) as string) <-- at 01 Jan 2001
00:00:01.0
& " " & (year of (current date) as string) & " - " &
time string of (current date)
Which would produce the date "31 Jan 2001 - 00:00:01"; not at all right.
So just allow yourself to use two lines, and say,
set now to current date
set theName to day of now...
You can "factor out" the "now" with a tell statement, but some people find these
forms very confusing.
tell now to set theName to its day as string & " " & [...] & its year as
string & [...]
You can be more efficient and probably more succinct and clear if you say "text
from 1 to 3 of (month of now as string)" instead of "characters 1 thru 3".
(Characters 1 thru 3 produces a list of characters, which you have to smash back
together into a string. "text from 1 to 3" produces a string with no need for
coercion.
Some people would let many of the "as string" coercions be implicit. If you
start with a string, everything appended to the end is coerced to a string.
Some other writers use the idiom
"" & a & b
to coerce and concatenate a and b together into a string. I think this usage
looks weird, but it probably is clearer and more robust than just hoping a is
already a string.
So, here are some rewrites, with various levels of peculiar idiom included.
Assume each one is preceded by the line, "set now to current date". Each
example is all on one line.
#1. Explicit coercions (but no unneeded ones).
set theName to day of now as string & " " & text from 1 to 3 of (month of now
as string)
& " " & (year of now as string) & " - " & time string of now
#2. Implicit coercions
set theName to day of now as string & " " & text from 1 to 3 of (month of now
as string)
& " " & year of now & " - " & time string of now
#3. "Starter String" implicit coercions.
set theName to "" & day of now & " " & text from 1 to 3 of (month of now as
string)
& " " & year of now & " - " & time string of now
#4. "Factored out"
tell now to set theName to its day as string & " " & text from 1 to 3 of (its
month as string)
& " " & its year & " - " & its time string
# 5. The ultimate confuser. (#3 and #4 combined.)
tell now to set theName to "" & its day & " " & text from 1 to 3 of (its month
as string)
& " " & its year & " - " & its time string
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden