• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Create a folder with today's date as the folder name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Create a folder with today's date as the folder name


  • Subject: Re: Create a folder with today's date as the folder name
  • From: has <email@hidden>
  • Date: Mon, 11 Feb 2002 15:07:27 +0000

Michelle Steiner wrote:
>
>On 2/10/02 6:18 AM, has <email@hidden> wrote:
>
>>Out of interest... I was poking around looking for the fastest way of
>>getting a month as integer (French Vanilla [above], iterating across a list
>>of months looking for a match, etc) and found the following to be quickest
>>overall:
>
>Even for December? It has to evaluate 12 if-then statements to get to
>December.

Both methods took the same amount of time to get October. November and
December were a bit slower, but on average the routine was a good bit
quicker. Course, if I weren't such a numpty and used an if...elseif...
block to begin with it'd probably outstrip FV even unto the twelveth month.


>I found that this code works quite well, and quite fast:
>
>set theMonth to text 1 through 3 of (month of (current date) as text)
>set allTheMonths to "JanFebMarAprMayJunJulAugSepOctNovDec"
>set monthInteger to ((offset of theMonth in allTheMonths) + 2) div 3

Very handy trick. I use a very similar 'get offset in string' technique in
my pseudo-hashes - damned useful and much quicker and easier to write than
a real hashing routine.


>And it's about the shortest code to type for this evaluation. In fact,
>it can be shortened to the following, if you like:

Short code has its advantages too, although I found this method was much
slower in practice. Depends what you need: the stuff I'm doing is for
repeated use, so needs to be fast as possible; for one-off datestamps and
the like where speed is not important, I'd tend to use the most compact
code to keep my script smaller.

BTW, one other wee thing about your method: coercing month constants to
strings doesn't work prior to [IIRC] OS8.5 so you couldn't use this routine
on older machines. Given the choice, I'd probably use the
iterate-across-a-list approach: it's pretty compact, totally robust and
reasonably fast. Or FV, as long as I knew it wasn't going to get passed
dates that'd break it.

======================================================================

on monthAsInteger(theMonth)
repeat with m from 1 to 12
if {January, February, March, April, May, June, July, August,
[NO-BREAK]September, October, November, December}'s item m is
[NO-BREAK]theMonth then return m
end repeat
error "Not a month."
end monthAsInteger

======================================================================

HTH

has
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Create a folder with today's date as the folder name
  • Next by Date: Re: Create a folder with today's date as the folder name
  • Previous by thread: Re: Create a folder with today's date as the folder name
  • Next by thread: Re: Create a folder with today's date as the folder name
  • Index(es):
    • Date
    • Thread