
Search

Support DFF
If you shop at Amazon anyway,
consider using this link. We receive a few cents from each purchase.
Thanks.
Support DFF
If you benefit from the website, in terms of
knowledge, entertainment value, or something otherwise useful,
consider making a donation via PayPal to help defray the
costs. (No PayPal account necessary to donate via credit
card.) Transaction is secure.

Contact
Feedback:
Send an e-mail with your
comments about this program (or anything else).

|
| |
Problem Description
Here's a program to find dates meeting constraints
on month of year, day of month, or day of week within a given range of
years.
Background & Techniques
Today being Friday the 13th, I was looking for an excuse to
introduce the grandkids to the word meaning "fear of Friday the 13th",
friggatriskaidekaphobia. I was going to send an email
telling them that it would be a good excuse to stay home from school today.
I didn't think of it in time, but it did arouse my curiosity about
future occurrences.
That led me to spend couple of hours coding the program posted here.
The problem was generalized to display a schedule of dates meeting the
conditions described above.
Notes for programmers
From the programming point of view, it was
fun discover Delphi date formatting routines which simplify operations such
as testing a day, month, and year set for validity or for incrementing a
date by a month.
The program has about 100 lines of code of which 30
were generated by Delphi. Most of the other 70 written by me were
comments lines or gathering information from the input controls before we
start the date testing loop. The loop logic looks has about 20 lines
of code and works like this: (User inputs are in red)
- Initialize a day, month, and year based on
user inputs
- Convert the day, month year fields to a date
field
- If the day of week of the date matches the
user input day of week request,
or the user said any day of week
was OK, display the date as a match.
- If any day of the
month is OK, then
 | If any month
is OK then increment date by one day
(making a new day, month, and year), |
 | Otherwise a specific month
was requested, so
set the day back to 1 and ncrement the year by 1 (making a new day, month , and year). |
otherwise a specific day of the month
was requested and we check this
 | If any month
is OK then increment the date by a month (making a new day, month
and year). |
 | Otherwise a
specific month was requested, so
increment the date by a year (making a new day, month , and year). |
If the year of the new date is less than or
equal to stop year, and the requested number of results has
been met, then loop back to Step 2.
The above loop logic required about 20 lines of
code and was the most fun to write and debug.
Running/Exploring the Program
Suggestions for Further Explorations
Add other variable Holiday date options
(Thanksgiving, Easter, those moved to a particular Monday of the month to
make more long weekends, etc.)
|
Original Date: February 13, 2009 |
Modified:
February 13, 2009 |
|
|