RE: filename/date validation [was: RE: applescript-users digest
RE: filename/date validation [was: RE: applescript-users digest
- Subject: RE: filename/date validation [was: RE: applescript-users digest
- From: Nigel Garvey <email@hidden>
- Date: Mon, 15 Apr 2002 10:21:46 +0100
has wrote on Fri, 12 Apr 2002 20:30:21 +0100:
>
Steve Suranie wrote:
>
>
>Hi folks:
>
>
>
>I'm writing a script of which a portion validates file names of a file.
>
>The file name structure is as follows:
>
>
>
>NP041102_IL_DESCRIPTION.tif
>
[...]
>
>I'm getting stumped at how to validate the date.
[...]
>
Otherwise (and just to head Nigel Garvey off at the pass here;) if pure,
>
unadulterated speed is what you need most then you'll most likely want to
>
roll your own custom-tailored routine:
[...]
>
on daysInMonth(theDate) -- modified from Nigel Garvey's Date Tips
>
copy theDate to d
>
tell d
>
set day to 32
>
set day to 1
>
day of (it - days)
>
end tell
>
end daysInMonth
Thanks for the plug. :-) I'm currently in the throes (in my spare time)
of revising some of my stuff. The new version of 'daysInMonth' doesn't
perform significantly better than the original, but its wording makes me
smile:
on daysInMonth for theDate -- returns an integer
copy theDate to d
set d's day to 32
(d - (d's day) * days)'s day
end daysInMonth
In has's "roll-your-own" script, the output from daysInMonth is compared
with a day number to check that that number is not too high for the
particular month. In fact, only about two thirds of this process is
necessary:
on dayIsInMonth(theDate, theDay)
copy theDate to d
set d's day to theDay
d's month is theDate's month -- d's month changes if theDay is too
high
end dayIsInMonth
if not dayIsInMonth(newDate, theDay) then error number -1700
NG
_______________________________________________
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.