Fixed leap time calculation; tested unixtimestamp convertion for the years 2016 to 2020
This commit is contained in:
52
unit/generateUnixtimes.sh
Executable file
52
unit/generateUnixtimes.sh
Executable file
@@ -0,0 +1,52 @@
|
||||
#/bin/bash
|
||||
|
||||
# date command is all we need, as shown:
|
||||
#date -d '2007-011-01 17:30:24' '+%s'
|
||||
#1193934624
|
||||
#date -d '2007-011-01 17:30:24' '+%w'
|
||||
#4
|
||||
|
||||
# Usage:
|
||||
# Call this script and write the output of stdout into a file.
|
||||
# e.g.: ./generateUnixtime.sh > unixtimetest.lua
|
||||
|
||||
# Generate the header
|
||||
cat << EOF
|
||||
dofile("../timecore.lua")
|
||||
function checkUnixTime(resultYear, resultMonth, resultDay, resultHour, resultMinute, resultSecond, resultDow, unixtime)
|
||||
year, month, day, hour, minute, second, dow = gettime(unixtime)
|
||||
|
||||
if not (year == resultYear and resultMonth == month and day == resultDay and hour == resultHour and minute == resultMinute and second == resultSecond and dow == resultDow) then
|
||||
print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " day of week : " .. resultDow .. " not extracted from " .. unixtime)
|
||||
print(year .. "-" .. month .. "-" .. day .. " " .. hour .. ":" .. minute .. ":" .. second .. " day of week : " .. dow .. " found instead")
|
||||
os.exit(1)
|
||||
else
|
||||
print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " OK")
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
EOF
|
||||
|
||||
# Generate all the tests
|
||||
for year in {2016..2020}; do
|
||||
for month in {1..12}; do
|
||||
for day in {1..31}; do
|
||||
hour=$((RANDOM%24))
|
||||
minutes=$((RANDOM%60))
|
||||
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"
|
||||
else
|
||||
unixtime=$(date -u -d "$timestmp" '+%s')
|
||||
dayofweek=$(date -u -d "$timestmp" '+%w')
|
||||
# Generate the lua test command, like: checkTime(2015, 1, 1, 10, 11, 12, 0, 1)
|
||||
echo "checkUnixTime($year, $month, $day, $hour, $minutes, $seconds, $dayofweek, $unixtime)"
|
||||
|
||||
fi
|
||||
done
|
||||
done
|
||||
done
|
||||
exit 0
|
1874
unit/testUnixtimes.lua
Normal file
1874
unit/testUnixtimes.lua
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user