2016-04-17 15:37:25 +02:00
|
|
|
#/bin/bash
|
|
|
|
|
|
|
|
# date command is all we need, as shown:
|
|
|
|
#date -d '2007-011-01 17:30:24' '+%:z'
|
|
|
|
#+01:00
|
|
|
|
|
|
|
|
HEAD=timetest_head.template
|
|
|
|
TAIL=timetest_tail.template
|
2016-04-17 16:21:01 +02:00
|
|
|
# remove the tailing "./" and the extension of this script
|
2016-04-17 15:37:25 +02:00
|
|
|
OUTPUT="$(echo "$0" | sed 's;^./;;' | cut -d'.' -f1).lua"
|
2016-04-17 15:53:16 +02:00
|
|
|
#rename OUTPUT from generate to test
|
2016-04-17 16:07:51 +02:00
|
|
|
OUTPUT="$(echo "$OUTPUT" | sed 's;generate;test;')"
|
2016-04-17 15:37:25 +02:00
|
|
|
|
|
|
|
echo "Generating $OUTPUT ..."
|
|
|
|
cat $HEAD > $OUTPUT
|
|
|
|
# Logic to generate the script
|
2016-04-17 15:50:52 +02:00
|
|
|
for year in {2016..2100}; do
|
|
|
|
echo "For $year ..."
|
2016-04-17 15:37:25 +02:00
|
|
|
for month in 3 10; do
|
|
|
|
for day in {1..31}; do
|
2016-04-17 16:07:51 +02:00
|
|
|
for hour in {0..23}; do
|
|
|
|
minutes=$((RANDOM%60))
|
2016-04-17 15:37:25 +02:00
|
|
|
seconds=$((RANDOM%60))
|
|
|
|
timestmp="$year-$month-$day $hour:$minutes:$seconds"
|
|
|
|
date -d "$timestmp" "+%F %T" >> /dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "--Time $timestmp is not valid" >> $OUTPUT
|
|
|
|
else
|
|
|
|
# Result of date looks like +01:00
|
|
|
|
# Grep extracts the hour, then remove the plus in front and at the end remove leading zeros
|
|
|
|
offset=$(date -d "$timestmp" '+%:z' | grep -o "+[0-9]*" | sed 's/+//' | sed 's/^0//')
|
|
|
|
dayofweek=$(date -d "$timestmp" '+%u')
|
|
|
|
# Generate the lua test command, like: checkTime(2015, 1, 1, 10, 11, 12, 0, 1)
|
|
|
|
echo "checkTime($year, $month, $day, $hour, $minutes, $seconds, $dayofweek, $offset)" >> $OUTPUT
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
done
|
|
|
|
done
|
|
|
|
cat $TAIL >> $OUTPUT
|
|
|
|
|
2016-05-15 15:44:19 +02:00
|
|
|
echo "---------------------------"
|
|
|
|
echo "Usage:"
|
2016-05-15 16:06:09 +02:00
|
|
|
echo "Call >lua $OUTPUT< in the terminal to execute the test"
|
2016-05-15 15:44:19 +02:00
|
|
|
|
2016-04-17 15:37:25 +02:00
|
|
|
exit 0
|