#!/bin/bash

# ------------------------------------------------------------
# RPC Project :
# RPC_list_days_of_month : return list of days in a month
# as "01 02.... 29 30" according month and year
# (Leap year taking into account)
# syntax : RPC_list_days_of_month year month
#      ex: RPC_list_days_of_month 1997 11
# P. Robert, LPP, 2013-01-29
# ------------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36`
Narg=2

if( (test $# = 1 ) && (test $1 = -h ) ) ; then hh=1 ; else hh=0 ; fi

if test $# != $Narg || test $hh = 1
   then
   echo "$appli : return list of days in a month"
   echo "as "01 02.... 29 30" according month and year"
   echo "$appli   require $Narg argument(s), ex:"
   echo "$appli   year month"
   echo "    ex: $appli 1997 11"
   echo "    ex: (1971 < year < 2059)"
   echo ""
   if test $hh = 1 ; then exit 0 ; fi
   echo " $appli36 : *** ERROR ! Command aborted." >&2
   exit 1
fi


yyc=$1
mmc=$2

# check input date validity
# -------------------------

if ((test $yyc -lt 1972) || (test $yyc -gt 2058))
   then 
        echo "year must be >= 1972 and =< 2058"
        echo "$appli36 : *** ERROR ! Command aborted." >&2
        exit 2
fi

if ((test $mmc -lt 1) || (test $mmc -gt 12))
   then 
       echo "month must be >= 1 and =< 12"
       echo ""
       echo "$appli36 : *** ERROR ! Command aborted." >&2
       exit 3
fi

# compute nb day in the given month
# ---------------------------------

nbj=`RPC_nday_of_month $yyc $mmc`

list="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28"

if test $nbj = 29
   then
   list="$list 29"
fi

if test $nbj = 30
   then 
   list="$list 29 30"
fi

if test $nbj = 31
   then 
   list="$list 29 30 31"
fi

echo $list
# ------------------------------------------------------------
