#!/bin/bash

find --version
echo; echo
date --iso-8601=seconds
echo; echo
echo '#### BEGIN TEST -mtime ###';
rm -f x*
touch -d '-60 hour' 'x5';
touch -d '-48 hour' 'x4';
touch -d '-36 hour' 'x3';
touch -d '-24 hour' 'x2';
touch -d '-12 hour' 'x1';
touch -d 'now' 'x0';
stat x*;
echo; echo '=== -mtime 2 ==='; find x* -mtime 2; echo 'EXPECTED: x5, x4';
echo; echo '=== -mtime 1 ==='; find x* -mtime 1; echo 'EXPECTED: x3, x2';
echo; echo '=== -mtime 0 ==='; find x* -mtime 0; echo 'EXPECTED: x1, x0';
echo; echo '=== -mtime +2 ==='; find x* -mtime +2; echo 'EXPECTED: x5 (x4) if AGE unrounded; otherwise: NONE';
echo; echo '=== -mtime -2 ==='; find x* -mtime -2; echo 'EXPECTED: x3, x2, x1, x0';
echo; echo '=== -mtime +1  ==='; find x* -mtime +1; echo 'EXPECTED: x5,x4,x3,(x2) if AGE undrounded; otherwise x5,(x4)';
echo; echo '=== -mtime -1  ==='; find x* -mtime -1; echo 'EXPECTED: x1, x0';
echo; echo '=== -mtime -2 -mtime +1 ==='; find x* -mtime -2 -mtime +1; echo 'EXPECTED: x3,(x2) if AGE is unrounded; otherwise NONE';
echo; echo '=== -mtime +1 -mtime -1 ==='; find x* -mtime -1 -mtime +1; echo 'EXPECTED: NONE';
echo '#### END TEST -mtime ###';

echo '#### BEGIN TEST -daystart -mtime ###';
rm -f x*
touch -d '00:00:00.000000 tomorrow -60 hour' 'x5';
touch -d '00:00:00.000000 tomorrow -48 hour' 'x4';
touch -d '00:00:00.000000 tomorrow -36 hour' 'x3';
touch -d '00:00:00.000000 tomorrow -24 hour' 'x2';
touch -d '00:00:00.000000 tomorrow -12 hour' 'x1';
touch -d '00:00:00.000000 tomorrow' 'x0';
stat x*;
echo; echo '=== -daystart -mtime 2 ==='; find x* -daystart -mtime 2; echo 'EXPECTED: x5, x4';
echo; echo '=== -daystart -mtime 1 ==='; find x* -daystart -mtime 1; echo 'EXPECTED: x3, x2';
echo; echo '=== -daystart -mtime 0 ==='; find x* -daystart -mtime 0; echo 'EXPECTED: x1, x0';
echo; echo '=== -daystart -mtime +2 ==='; find x* -daystart -mtime +2; echo 'EXPECTED: x5 (x4) if AGE unrounded; otherwise: NONE';
echo; echo '=== -daystart -mtime -2 ==='; find x* -daystart -mtime -2; echo 'EXPECTED: x3, x2, x1, x0';
echo; echo '=== -daystart -mtime +1  ==='; find x* -daystart -mtime +1; echo 'EXPECTED: x5,x4,x3,(x2) if AGE undrounded; otherwise x5,(x4)';
echo; echo '=== -daystart -mtime -1  ==='; find x* -daystart -mtime -1; echo 'EXPECTED: x1, x0';
echo; echo '=== -daystart -mtime -2 -daystart -mtime +1 ==='; find x* -daystart -mtime -2 -daystart -mtime +1; echo 'EXPECTED: x3,(x2) if AGE is unrounded; otherwise NONE';
echo; echo '=== -daystart -mtime +1 -daystart -mtime -1 ==='; find x* -daystart -mtime -1 -daystart -mtime +1; echo 'EXPECTED: NONE';
echo '#### END TEST -daystart -mtime ###';

echo '#### BEGIN TEST -mmin ###';
rm -f x*
touch -d '-150 sec' 'x5';
touch -d '-120 sec' 'x4';
touch -d '-90 sec' 'x3';
touch -d '-60 sec' 'x2';
touch -d '-30 sec' 'x1';
touch -d 'now' 'x0';
stat x*;
echo; echo '=== -mmin 2 ==='; find x* -mmin 2; echo 'EXPECTED: x5, x4';
echo; echo '=== -mmin 1 ==='; find x* -mmin 1; echo 'EXPECTED: x3, x2';
echo; echo '=== -mmin 0 ==='; find x* -mmin 0; echo 'EXPECTED: x1, x0';
echo; echo '=== -mmin +2 ==='; find x* -mmin +2; echo 'EXPECTED: x5 (x4) if AGE unrounded; otherwise: NONE';
echo; echo '=== -mmin -2 ==='; find x* -mmin -2; echo 'EXPECTED: x3, x2, x1, x0';
echo; echo '=== -mmin +1  ==='; find x* -mmin +1; echo 'EXPECTED: x5,x4,x3,(x2) if AGE undrounded; otherwise x5,(x4)';
echo; echo '=== -mmin -1  ==='; find x* -mmin -1; echo 'EXPECTED: x1, x0';
echo; echo '=== -mmin -2 -mmin +1 ==='; find x* -mmin -2 -mmin +1; echo 'EXPECTED: x3,(x2) if AGE is unrounded; otherwise NONE';
echo; echo '=== -mmin +1 -mmin -1 ==='; find x* -mmin -1 -mmin +1; echo 'EXPECTED: NONE';
echo '#### END TEST -mmin ###';


echo '#### BEGIN TEST -daystart -mmin ###';
rm -f x*
touch -d '00:00:00.000000 tomorrow -150 sec' 'x5';
touch -d '00:00:00.000000 tomorrow -120 sec' 'x4';
touch -d '00:00:00.000000 tomorrow -90 sec' 'x3';
touch -d '00:00:00.000000 tomorrow -60 sec' 'x2';
touch -d '00:00:00.000000 tomorrow -30 sec' 'x1';
touch -d '00:00:00.000000 tomorrow' 'x0';
stat x*;
echo; echo '=== -mmin 2 ==='; find x* -daystart -mmin 2; echo 'EXPECTED: x5, x4';
echo; echo '=== -mmin 1 ==='; find x* -daystart -mmin 1; echo 'EXPECTED: x3, x2';
echo; echo '=== -mmin 0 ==='; find x* -daystart -mmin 0; echo 'EXPECTED: x1, x0';
echo; echo '=== -mmin +2 ==='; find x* -daystart -mmin +2; echo 'EXPECTED: x5 (x4) if AGE unrounded; otherwise: NONE';
echo; echo '=== -mmin -2 ==='; find x* -daystart -mmin -2; echo 'EXPECTED: x3, x2, x1, x0';
echo; echo '=== -mmin +1  ==='; find x* -daystart -mmin +1; echo 'EXPECTED: x5,x4,x3,(x2) if AGE undrounded; otherwise x5,(x4)';
echo; echo '=== -mmin -1  ==='; find x* -daystart -mmin -1; echo 'EXPECTED: x1, x0';
echo; echo '=== -mmin -2 -mmin +1 ==='; find x* -daystart -mmin -2 -mmin +1; echo 'EXPECTED: x3,(x2) if AGE is unrounded; otherwise NONE';
echo; echo '=== -mmin +1 -mmin -1 ==='; find x* -daystart -mmin -1 -mmin +1; echo 'EXPECTED: NONE';
echo '#### END TEST -daystart -mmin ###';
