Re: Date - 1 day in Address Book
Re: Date - 1 day in Address Book
- Subject: Re: Date - 1 day in Address Book
- From: Paul Berkowitz <email@hidden>
- Date: Mon, 21 Jul 2003 10:02:46 -0700
On 7/21/03 8:42 AM, "Paul Berkowitz" <email@hidden> wrote:
>
------------------------------
>
>
set theBirthdate to (date stringDate) + (12 * hours)
>
set theBirthdate to my AdjustABForGMT(theBirthdate)
>
tell application "Address Book" to set birth date of abPerson to
>
theBirthdate
>
>
>
to AdjustABForGMT(theBirthdate) -- stupid bug in AB up to OS 10.2.x ?
>
>
local hexOS, unixSecs, theBirthdate
>
>
set unixSecs to theBirthdate - (date "Thursday, January 1, 1970 12:00:00
>
AM")
>
set unixSecs to my NumberToString(unixSecs)
>
>
set theBirthdate to do shell script "date -r " & unixSecs & " \"+" &
>
UFormat & " %T\""
>
set theBirthdate to date theBirthdate
>
>
return theBirthdate
>
>
end AdjustABForGMT
>
>
---------------------------------
Drat, I also included an undefined global 'UFormat'. There's yet another bug
which needs a workaround: the Unix 'locale' date constants and referents do
not work in OS X, Thus ï is _supposed_ to give you the local version - and
day/month order. According to man strftime:
"Additionally ï implemented to represent short month name / day
order of the date, ï to represent long month name / day order and %OB to
represent alternative months names (used standalone, without
day mentioned)."
But it doesn't work. So you need a routine to get the month and day order
correct there. The following routine is ultimately based on a great trick
worked out by Nigel Garvey a long time ago. Either make UFormat global, as
below, or call the handler from within the AdjustABForGMT(theBirthdate)
handler above.
---------------------------------
global UFormat
set UFormat to my UFormatDate()
to UFormatDate()
local testDate, UFormat, df
get "1/2/3"
tell AppleScript to set testDate to date (result)
set UFormat to ""
repeat with i from 1 to 3 -- as in "1/2/3"
if i = the day of testDate then
get "%d"
else if (i + 2000) = the year of testDate then
get "%Y"
else
get "%m"
end if
set UFormat to UFormat & the result & "/"
end repeat
set df to text 1 thru -2 of UFormat
return df
end UFormatDate
-----------------------------
--
Paul Berkowitz
_______________________________________________
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.