Re: Applescript Date Manipulation...
Re: Applescript Date Manipulation...
- Subject: Re: Applescript Date Manipulation...
- From: "Arthur J. Knapp" <email@hidden>
- Date: Mon, 23 Dec 2002 12:10:44 -0500
>
Date: Sat, 21 Dec 2002 14:19:36 +1100
>
Subject: Re: Applescript Date Manipulation...
>
From: Richard Morton <email@hidden>
>
On Saturday, December 21, 2002, at 01:00 PM, Domains4Days.com wrote:
>
> ... But I would really like it to look like:
>
> 12-20-02 5-54-00 PM ( short version - PC friendly)...
>
There are some handlers on The FooDoo Lounge that will pretty much do
>
http://home.netc.net.au/~sunreal/FooDooLounge/code/
>
date_handlers.html#nus
>
http://home.netc.net.au/~sunreal/FooDooLounge/code/
>
date_handlers.html#timeString
Good stuff. :)
I offer my own date-to-string handler. I have not yet taken the time
to optimize it, so I'll leave that as an exercise to our readers. ;-)
on DateToString(sFormat, _d_)
(*
* yyyy 4 digit year
* yy 2 digit year
* mmmm full month name
* mmm 3 letter month name
* mm month, padded
* m month
* dddd full day name
* ddd 3 letter day name
* dd date, padded
* d date
* hh hour, padded
* h hour
* HH hour, 24, padded
* H hour, 24
* MM minutes, padded
* M minutes
* ss seconds, padded
* s seconds
* ?m am/pm
* ` escape character
* ~ null character
*)
if (_d_'s class = date) then
set d to _d_
else
set d to current date
end if
if (sFormat's class is not string) or ,
(sFormat's length = 0) then return d as string --> default
set s to sFormat & " " --> prevent out-of-bounds in parsing
set t to ""
considering case
repeat until s's length < 5
if (s starts with "yy") then
set v to d's year as string
if (s starts with "yyyy") then
set t to t & v
set s to s's text 5 thru -1
else
set t to t & v's text -2 thru -1
set s to s's text 3 thru -1
end if
else if (s starts with "m") then
if (s starts with "mmm") then
set v to d's month as string
if (s starts with "mmmm") then
set t to t & v
set s to s's text 5 thru -1
else
set t to t & v's text 1 thru 3
set s to s's text 4 thru -1
end if
else
-- French Vanilla method, via Emmanual Levy
copy d to b
set b's month to January
set v to 1 + (d - b + 1314864) div 2629728
if (s starts with "mm") then
set t to t & ("0" & v)'s text -2 thru -1
set s to s's text 3 thru -1
else
set t to t & v
set s to s's text 2 thru -1
end if
end if
else if (s starts with "d") then
if (s starts with "ddd") then
set v to d's weekday as string
if (s starts with "dddd") then
set t to t & v
set s to s's text 5 thru -1
else
set t to t & v's text 1 thru 3
set s to s's text 4 thru -1
end if
else
set v to d's day as string
if (s starts with "dd") then
set t to t & ("0" & v)'s text -2 thru -1
set s to s's text 3 thru -1
else
set t to t & v
set s to s's text 2 thru -1
end if
end if
else if (s starts with "h") or (s starts with "H") then
set v to (d's time) div 60 div 60
if (s starts with "h") and (v > 12) then ,
set v to v - 12
ignoring case
if (s starts with "hh") then
set t to t & ("0" & v)'s text -2 thru -1
set s to s's text 3 thru -1
else
set t to t & v
set s to s's text 2 thru -1
end if
end ignoring
else if (s starts with "M") then
set v to (d's time) div 60 mod 60
if (s starts with "MM") then
set t to t & ("0" & v)'s text -2 thru -1
set s to s's text 3 thru -1
else
set t to t & v
set s to s's text 2 thru -1
end if
else if (s starts with "s") then
set v to (d's time) mod 60
if (s starts with "ss") then
set t to t & ("0" & v)'s text -2 thru -1
set s to s's text 3 thru -1
else
set t to t & v
set s to s's text 3 thru -1
end if
else if (s starts with "?m") then
if ((d's time) div 60 div 60 < 12) then
set t to t & "AM"
else
set t to t & "PM"
end if
set s to s's text 3 thru -1
else if (s starts with "`") then
set t to t & s's character 2
set s to s's text 3 thru -1
else if (s starts with "~") then
set s to s's text 2 thru -1
else
set t to t & s's character 1
set s to s's text 2 thru -1
end if
end repeat
end considering
return t
end DateToString
{ Arthur Knapp, of <
http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m
"Safe the Nature" - political graffiti in Prague
}
_______________________________________________
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.