Age & Anniversary Calculations
Igor de Oliveira Couto
igor at superstudent.net
Mon May 21 03:02:53 EDT 2012
Dear LC Folks,
What is the 'best' way to perform these 2 calculations with LiveCode?
1) Calculate a person's age, given a birthdate:
/*
Calculates the number of birthdays from a given date, up to and including *today*.
@param pBirthDate the birthdate
@return a positive integer representing the number of birthdays from pBirthDate to today.
*/
function currentAge pBirthDate
...?
end currentAge
2) Calculate whether an *anniversary* falls within a time frame - ie., within a week, within 2 weeks, within a month of today:
/*
Determines whether an anniversary date is close to a 'reference date'.
@param pAnniversaryDate the anniversary date
@param pReferenceDate the date that is supposed to be 'close' - or not - to the anniversary date
@pTimeFrame a time period, in seconds, that determines what 'close' is: it can be 1 day, 7 days, 1 month, etc.
@return a boolean: if the anniversary date is sufficiently 'close' (as specified by pTimeFrame) to the reference date,
then it returns TRUE, otherwise it returns FALSE.
*/
function isAnniversaryClose pAnniversaryDate, pReferenceDate, pTimeFrame
...?
end isAnniversaryClose
I'm not being lazy, but the algorithms I came up with look so 'convoluted' that I *know* there must be an easier way. I know that usually in every language there is a 'standard' or 'best-practice' way to perform these standard date calculations, so rather than re-inventing the wheel, I thought I'd run it by you, Masters, and be humbled by your experience! :-)
Many thanks in advance,
--
Igor Couto
Sydney, Australia
More information about the use-livecode
mailing list