#!/bin/sh
set -e
if [ $# -lt 1 ]; then
    echo "Start date missing"
    exit 1
fi

if [ $1 = '-h' -o $1 = '--help' ]; then
    echo "date range generator"
    echo "Usage:"
    echo "  Generate range from date until today:"
    echo "  $ daterange 2019-01-01"
    echo
    echo "  Generate range from date until end date:"
    echo "  $ daterange 2018-12-27 2019-01-04"
    exit
fi

start=$(date -I -d $1)

if [ $# -gt 1 ]; then
    end=$(date -I -d $2)
else
    end=`date -I`
fi

while test $(echo "$start" | tr -d -) -le $(echo "$end" | tr -d -); do
    echo "$start"
    start=$(date -I -d "$start + 1 day")
done
