Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Address Book plug-ins and 'custom date' fields' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Address Book plug-ins and 'custom date' fields
Authored by: BobVB on May 11, '04 07:00:58PM
Sorry, its just my code that figures out the days left is a nightmare and I think it doesn't even do it accurately in some cases. Here is a bit of code that illustrates what I'm talking about with 'custom date'

using terms from application "Address Book"
	on action property
		return "custom date"
	end action property
	on action title for p with e
		set theAge to my ageForDate(value of e)
		if label of e is equal to "Anniversary" then
			return "next is " & (theAge + 1 as string) & fancy(theAge + 1) & " anniversary"
			-- set theAge to theAge as string
			return (theAge as string) & " years since then"
		end if
	end action title
	on should enable action for p with e
		return false
	end should enable action
	on perform action for p with e
		return true
	end perform action
end using terms from

on ageForDate(e)
	set d to current date
	set age to (year of d) - (year of e)
	if month of d < month of e then set age to age - 1
	if (month of d = month of e) and (day of d < day of e) then set age to age - 1
	return age
end ageForDate

on fancy(num)
	set idstr to "stndrdth"
	set wnum to (num mod 100)
	if (wnum > 10) and (wnum < 14) then
		set myend to "th"
		set wnum to ((((num mod 10) - 1) * 2) + 1)
		if wnum > 5 then
			set myend to "th"
			set myend to characters wnum thru (wnum + 1) of idstr as string
		end if
	end if
	return myend
end fancy

[ Reply to This | # ]