Hi Carol, et al,
I'm back to work on my membership database of personal profiles.
It's for a parents' support group with one record/profile for each family. I want to add a text field named 'Children' that will function in the following way:
1. When a member creates their record, they are instructed to fill out this field with their children's names and birthdates, for example:
"Tommy (09-Feb-1993), Jenny (30-Apr-1998), expecting baby (01-Jan-2000)"
2. The exact formatting is not important except for the dates, i.e., it doesn't matter if they put the date in parentheses, or commas between names. How to format the date as dd-mmm-yyyy will be clearly specified in the instructions.
3. The field data will be stored in the database file as is, but the dates will be converted to and replaced with current ages each time the record is viewed. So, based on today's date of 27-Aug-1999, the following would be displayed:
"Children: Tommy (6.5 yrs), Jenny (16 mos), expecting baby (01-Jan-2000)"
4.a. From the above example, you can see that any date in the future is left unchanged.
b. Birthdates formatted incorrectly are also be left as is; I don't want a lot of fancy error checking, and they can always modify their record if they screw up the date format.
c. If the age is 2 yrs or higher, it is shown in years (nearest tenth of a year).
d. If the age is between 8 weeks and 2 yrs, it is shown in months (nearest whole month).
e. If the age is between 2 and 8 weeks, it is shown in weeks (nearest whole week).
f. If the age is less than 2 weeks, it is shown in days.
The age calculations need not be precise. I don't know Perl syntax very well, but here's a starting point:
for each occurence of a text string that matches the pattern dd-mmm-yyyy {
assume it's a birthdate
calculate the age IN DAYS and round to the nearest integer
if age >= 0 {
if age >= 730 {
divide age by 365.25 and round it to the nearest tenth
change units to "yrs" }
else if age > 56 {
divide age by 30.44 and round it to the nearest integer
change units to "mos" }
else if age >= 14 {
divide age by 7 and round it to the nearest integer
change units to "wks" }
else { if age = 1, change units to "day", else change units to "days" }
concatenate age and units, and replace the matched pattern with the result
}
}Can someone help me flesh out the Perl code for this? I suppose it would be part of sub html_record in html.pl (I'm using the user-friendly version with my own html formatting, i.e., no auto-generated html).
Thanks in advance!
Scott Noelle,
noelles@teleport.com
I'm back to work on my membership database of personal profiles.
It's for a parents' support group with one record/profile for each family. I want to add a text field named 'Children' that will function in the following way:
1. When a member creates their record, they are instructed to fill out this field with their children's names and birthdates, for example:
"Tommy (09-Feb-1993), Jenny (30-Apr-1998), expecting baby (01-Jan-2000)"
2. The exact formatting is not important except for the dates, i.e., it doesn't matter if they put the date in parentheses, or commas between names. How to format the date as dd-mmm-yyyy will be clearly specified in the instructions.
3. The field data will be stored in the database file as is, but the dates will be converted to and replaced with current ages each time the record is viewed. So, based on today's date of 27-Aug-1999, the following would be displayed:
"Children: Tommy (6.5 yrs), Jenny (16 mos), expecting baby (01-Jan-2000)"
4.a. From the above example, you can see that any date in the future is left unchanged.
b. Birthdates formatted incorrectly are also be left as is; I don't want a lot of fancy error checking, and they can always modify their record if they screw up the date format.
c. If the age is 2 yrs or higher, it is shown in years (nearest tenth of a year).
d. If the age is between 8 weeks and 2 yrs, it is shown in months (nearest whole month).
e. If the age is between 2 and 8 weeks, it is shown in weeks (nearest whole week).
f. If the age is less than 2 weeks, it is shown in days.
The age calculations need not be precise. I don't know Perl syntax very well, but here's a starting point:
Code:
variables: birthdate, age, units for each occurence of a text string that matches the pattern dd-mmm-yyyy {
assume it's a birthdate
calculate the age IN DAYS and round to the nearest integer
if age >= 0 {
if age >= 730 {
divide age by 365.25 and round it to the nearest tenth
change units to "yrs" }
else if age > 56 {
divide age by 30.44 and round it to the nearest integer
change units to "mos" }
else if age >= 14 {
divide age by 7 and round it to the nearest integer
change units to "wks" }
else { if age = 1, change units to "day", else change units to "days" }
concatenate age and units, and replace the matched pattern with the result
}
}
Thanks in advance!
Scott Noelle,
noelles@teleport.com