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