encourage:
I've never seen a good solution to this question in unix shell. Over the years, I've collected several utilities in "C" (written by guys smarter than me) that answer this question, and other date related questions.
Provide an email address, and I'll send you the "C" source.
Regards,
Ed
Schaefer