I've thought about that on and off for a while... never realized there was a name for the day though! :-) Very cool script, also! Regards, Andrew On Wed, Sep 4, 2013 at 5:42 PM, Mike Miller <mbmiller+l at gmail.com> wrote: > For any two people there exists a date on which the older one is exactly > twice the age of the younger one. I'll call this their "doubling day." > > The interesting thing is that this is the same day on which the younger > one is exactly the age that the older one was when the younger one was > born. It is also the day on which the older one is exactly twice as old as > he or she was when the younger one was born. It is fun to figure this out > for parent and offspring. Here is an example: > > My wife's birthday: > > bday1="15 Sep 1969" > > My daughter's birthday: > > bday2="18 Sep 2007" > > The day when my daughter will be the age my wife was when my daughter was > born: > > $ date -d "$bday2 +$(echo $(date -d "$bday1" +'%s') $(date -d "$bday2" > +'%s') | awk '{print $2-$1}') seconds" +"%A, %B %d, %Y" > Wednesday, September 20, 2045 > > So on that date, my wife will be twice the age she was when our daughter > was born, our daughter will be half her mother's age, and our daughter will > be the age her mother was when our daughter was born. > > I got more into it and made the script below. It seems to deal with time > zones correctly. Let me know what you think. Thanks. > > Mike > > > #!/bin/bash > > # Enter two birthdays, get back the date and time on which the older > # individual is exactly double the age of the younger individual. > # > # When neither birthdate includes a time of day, both birth times are > # set to 12:01 PM in the locale time zone. I wanted to use noon -- the > # middle of the day -- but there is some ambiguity about whether noon > # is a.m. or p.m., so I changed the time to 12:01 p.m. > # > # Input dates are accepted in any format that "date" can understand. > # For example these work for me in my locale and give the same answer: > # # 23 Mar 1992 > # 1992-03-23 > # 3/23/1992 > # > # The third example input date works in my US locale, but it won't > # work in many parts of the world because the order of month and day > # needs to be reversed (e.g., in Latin America and Europe). > # > # A time can be specified along with a time zone. Examples: > # > # "19 May 1958 17:00' "23 Mar 1992 20:00" > # > # 'TZ="America/Chicago" 19 May 1958 17:00' "23 Mar 1992 21:00 EST" > # > # If your machine is set to the America/Chicago (Central) time zone, > # those two pairs of dates do the same thing. > # > # The output time zone can be specified as a third argument, but it > # must be provided in the format described in timezone(3) or > # tzfile(5). The easy way to figure it out is to run the command > # tzselect or try this nice web site: > # > # http://www.timezoneconverter.**com/cgi-bin/findzone.tzc<http://www.timezoneconverter.com/cgi-bin/findzone.tzc> > # > > > if [ $# -gt 2 ]; then > TZ=$3 > if [ -f /usr/share/zoneinfo/$TZ ] ; then > export TZ > else > echo " > ERROR: unacceptable time zone specified. Try this website: > http://www.timezoneconverter.**com/cgi-bin/findzone.tzc<http://www.timezoneconverter.com/cgi-bin/findzone.tzc>" > 1>&2 ; exit 1 > fi > fi > > input_bday1=$1 > input_bday2=$2 > > # Figure out the time > > time1=$(date -d "$input_bday1" +%T) > time2=$(date -d "$input_bday2" +%T) > > # When only date, and not time, is specified, time reverts by default > # to zero, which is midnight on the morning of the given day. It is > # better to use noon when the time is not known, so here we change the > # time to one minute after noon (so that AM/PM are clear to the user). > # This code also puts the dates into seconds from 1970-01-01 00:00:00 UTC. > > if [ "$time1" == "00:00:00" ] ; then > bday1=$(date -d "$input_bday1 +12 hours +1 minute" +%s) > else > bday1=$(date -d "$input_bday1" +%s) > fi > > > if [ "$time2" == "00:00:00" ] ; then > bday2=$(date -d "$input_bday2 +12 hours +1 minute" +%s) > else > bday2=$(date -d "$input_bday2" +%s) > fi > > > # Compute the doubling day in seconds: > > let "doubling_day = 2*bday2 - bday1" > > # Generate output: > > echo "Birthday #1 = $(date -d @$bday1 +"%A, %B %d, %Y, %r %Z")" > echo "Birthday #2 = $(date -d @$bday2 +"%A, %B %d, %Y, %r %Z")" > echo "Doubling day = $(date -d @$doubling_day +"%A, %B %d, %Y, %r %Z")" > ______________________________**_________________ > TCLUG Mailing List - Minneapolis/St. Paul, Minnesota > tclug-list at mn-linux.org > http://mailman.mn-linux.org/**mailman/listinfo/tclug-list<http://mailman.mn-linux.org/mailman/listinfo/tclug-list> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mailman.mn-linux.org/pipermail/tclug-list/attachments/20130904/a5423afc/attachment.html>