#!/bin/bash
## does date-arithmetic in days;  Eugene Reimer  2008;
## relies on gnu-date allowing large timezone values;
## another possibly more portable method would use +%s format, then do arithmetic in seconds;
##
## USAGE EXAMPLES:
##	dateplusdays  20081220  -1		-- produces 20081219
##	dateplusdays  20081220  -20		-- produces 20081130

FMT=+%Y%m%d;  [ $# -eq 3 ] && FMT=$3		##FMT is optional 3rd param
TZ=$2;  ((TZ=TZ*-2400));  if ((TZ>=0));then TZ=+$TZ; fi
date -u -d "$1 00:00:00 $TZ"  "$FMT"
