[wplug] Determine the "Last Full Week" of the month

Kevin Squire gentgeen at wikiak.org
Wed Oct 20 22:04:43 EDT 2010


On Wed, 20 Oct 2010 10:08:53 -0400
Eric Cooper <ecc at cmu.edu> wrote:

> On Wed, Oct 20, 2010 at 09:37:10AM -0400, Kevin Squire wrote:
> > I have to work out a script (prefer bash in this case, but any will
> > work) for work that will run on the 1 day of the week (sunday) but
> > ONLY if it is the last full week of the month.
> 
> I think a simpler test is:
> 
> today is Sunday AND next Saturday (today + 6) is still in the current
> month AND the Saturday after that (today + 13) is no longer in the
> current month
> 
> Here's a script using the wonderful date parsing of the "date"
> command:
> 
> #!/bin/sh
> 
> if [ $# -ne 1 ]; then
>     echo Usage: $0 date
>     exit 1
> fi
> 
> day="$1"
> 
> if [ $(date --date "$day" +%A) != Sunday ]; then
>     echo $day is not a Sunday
>     exit 1
> fi
> 
> month=$(date --date "$day" +%B)
> 
> if [ $(date --date "$day + 6 days" +%B) != $month ]; then
>     echo $day is not in a full week
>     exit 1
> fi
> 
> if [ $(date --date "$day + 13 days" +%B) = $month ]; then
>     echo $day is not in the last week
>     exit 1
> fi
> 
> echo $day is the Sunday of the last full week of $month
> exit 0
> 

Perfect!  and it gets around my problem with "If month as more then 31
days" 

Thank you so much to everyone that replied.

-- 
http://www.wikiak.org

#############################################################
 Associate yourself with men of good quality if you esteem    
 your own reputation; for 'tis better to be alone then in bad 
 company.        - George Washington, Rules of Civility


More information about the wplug mailing list