Subject: | |
From: | |
Reply To: | |
Date: | Wed, 21 May 2003 14:08:03 -0400 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
On Wednesday, May 21, 2003, at 11:56 AM, Eric Schult wrote:
> Another crutch upon which have propped myself up is the dateToStamp and
> stampToDate commands in Tanaka's OSAX, and it's not immediately clear
> to me if
> there's an alternate way in OS X to handle date manipulations like
> that.
>
> For example, if I want to coerce a a string (i.e. "mmddyyyy") into a
> date, I'm
> completely beholden to Tanaka's to do that.
>
> Any clues?
>
It can be done in vanilla applescript. It won't be fast.
on mm_to_date(aDate)
if month of aDate = January then return "01"
if month of aDate = February then return "02"
if month of aDate = March then return "03"
if month of aDate = April then return "04"
if month of aDate = May then return "05"
if month of aDate = June then return "06"
if month of aDate = July then return "07"
if month of aDate = August then return "08"
if month of aDate = September then return "09"
if month of aDate = October then return "10"
if month of aDate = November then return "11"
if month of aDate = December then return "12"
end mm_to_date
on m_to_date(aDate)
if month of aDate = January then return "1"
if month of aDate = February then return "2"
if month of aDate = March then return "3"
if month of aDate = April then return "4"
if month of aDate = May then return "5"
if month of aDate = June then return "6"
if month of aDate = July then return "7"
if month of aDate = August then return "8"
if month of aDate = September then return "9"
if month of aDate = October then return "10"
if month of aDate = November then return "11"
if month of aDate = December then return "12"
end m_to_date
on dd_to_date(aDate)
if day of aDate < 10 then
return "0" & day of aDate
else
return "" & day of aDate
end if
end dd_to_date
on d_to_date(aDate)
return "" & day of aDate
end d_to_date
on yyyy_to_date(aDate)
return "" & year of aDate
end yyyy_to_date
on yy_to_date(aDate)
set temp to (year of aDate) mod 100
if temp < 10 then
return "0" & temp
else
return "" & temp
end if
end yy_to_date
on parse_date_string(aString, aDate)
set tid to AppleScript's text item delimiters
if aString contains "yyyy" then
set AppleScript's text item delimiters to "yyyy"
set aString to every text item of aString
set AppleScript's text item delimiters to yyyy_to_date(aDate)
set aString to aString as text
end if
if aString contains "yy" then
set AppleScript's text item delimiters to "yy"
set aString to every text item of aString
set AppleScript's text item delimiters to yy_to_date(aDate)
set aString to aString as text
end if
if aString contains "mm" then
set AppleScript's text item delimiters to "mm"
set aString to every text item of aString
set AppleScript's text item delimiters to mm_to_date(aDate)
set aString to aString as text
end if
if aString contains "m" then
set AppleScript's text item delimiters to "m"
set aString to every text item of aString
set AppleScript's text item delimiters to m_to_date(aDate)
set aString to aString as text
end if
if aString contains "dd" then
set AppleScript's text item delimiters to "dd"
set aString to every text item of aString
set AppleScript's text item delimiters to dd_to_date(aDate)
set aString to aString as text
end if
if aString contains "d" then
set AppleScript's text item delimiters to "d"
set aString to every text item of aString
set AppleScript's text item delimiters to d_to_date(aDate)
set aString to aString as text
end if
set AppleScript's text item delimiters to tid
return aString
end parse_date_string
log parse_date_string("yyyymd", current date)
log parse_date_string("yymmdd", current date)
log parse_date_string("yyyymd", date "Tuesday, October 16, 1973
12:00:00 AM")
log parse_date_string("yymmdd", date "Tuesday, October 16, 1973
12:00:00 AM")
(*2003521*)
(*030521*)
(*19731016*)
(*731016*)
I think I got it all. I just sat down and wrote that.
-Mark
|
|
|