Tuesday, May 30, 2006

highlight announcements timings rounding off

Modified our bash shell script to round off the highlight announcements timings to 15 minute intervals:

MINUTES=`echo "scale=1; ($MINUTES/15)" | bc -l`
MINUTES=$(printf "%2.0f" $MINUTES)
MINUTES=`echo "scale=0; ($MINUTES*15)" | bc -l`

if [ "$MINUTES" = "60" ]
then
HOURS=`echo "scale=0; ($HOURS+1)" | bc -l`
MINUTES=00
fi

if [ "$HOURS" = "24" ]
then
HOURS=00
fi

MINUTES=$(printf "%02d" $MINUTES)
HOURS=$(printf "%02d" $HOURS)
#this gets them the leading zeros

Earlier code was

MINUTES=`printf %02d $(echo "scale=0; ($MINUTES/5)*5" | bc -l)`

This only rounds DOWN to the nearest multiple of 5.
Never rounds up correctly.
(Edit for the leading zeros code: 1st June)

No comments:

Post a Comment