#! /bin/sh

set -ev

test $DARCS || DARCS=`pwd`/../darcs
darcs=$DARCS

if [ -e tmp ]; then
    rm -rf tmp;
fi
mkdir tmp
cd tmp
$darcs init
touch bar
$darcs add bar
$darcs record -a -m "" bar -A x

try_date() {
  # just be happy if it doesn't complain about the date being fancy
  $darcs changes --match="date \"$1\""
}

# FIXME: for now we only check for recognition, not for a correct parse!

# the comments about dates being the same are meant for some brave soul
# willing to implement more semantic tests

# alternately, it might be more useful to build a random date string generator
# using QuickCheck... for any n random CalendarTimes, have it generate some
# possible variants and roundtrip them to see if they match

# this block of dates should all refer to the same thing 
try_date '2007-01-01'
try_date '20070101'
try_date '2007-01'
try_date '200701'
try_date '2007'
# week dates. note that 2007 was tactically selected as it starts on Monday
try_date '2007-W01-1'
try_date '2007W011'
try_date '2007-W01'
# ordinal dates. eh... why not?
try_date '2007-001' # first day of 2005
try_date '2007001'

# midnight and zero
try_date '1992-10-14 24:00'
try_date '1992-10-15 00:00'
 
# all the same date/time
try_date '1992-02-12T22:32:11'
try_date '1992-02-12 22:32:11'
try_date '1992-02-12T223211.0000'

# english dates - the old hard coded from < darcs 1.0.6  
try_date 'today'
try_date 'yesterday'
try_date 'day before yesterday'
try_date 'last week'
try_date 'last month'

# english dates - new possibilities
try_date 'yesterday at 14:00:00'
try_date 'last 3 years'
try_date '2 days ago'
try_date 'last month 13:00' 
try_date '15 minutes after 1992-10-02'
try_date '3 days before last week'

# english intervals
try_date 'between last fortnight and yesterday'
try_date 'in the last 45 seconds'
try_date 'after 1992'

# iso 8601 intervals
try_date '1992-10-15 00:00Z/1992-10-15 00:01Z'
try_date 'P3YT3M/1992'
try_date '1992/P3Y3M4DT5H3M2S'
try_date '1992/P3Y3M'

# stuff from the manual
try_date 'between 2004-03-12 and last week'
try_date 'last week'
try_date 'yesterday'
try_date 'today 14:00'
try_date '3 days before last year at 17:00'
try_date 'Sat Jun  30 11:31:30 EDT 2004'
try_date 'after 2005'
try_date 'in the last 3 weeks'
try_date 'P3M/2006-03-17'
try_date '2004-01-02/2006-03-17'
try_date 'P2M6D'

# cvs dates 
try_date '2006/01/19 21:14:20 UTC'
try_date '2006/01/19 21:14:20 EST'
try_date '2006/01/19 21:14:20'

# cleanup
cd ..
rm -rf tmp
