Successfully tested unixtimestamp to UTC time convertion
This commit is contained in:
parent
34e3f1a78e
commit
b441e62a4d
@ -4,12 +4,14 @@ The tests were generated using the date command provided with linux.
|
|||||||
|
|
||||||
### Summer- Winter- Time calculation
|
### Summer- Winter- Time calculation
|
||||||
The file `testTimesMarchOctober.lua` tests all days in March and October until the year 2100.
|
The file `testTimesMarchOctober.lua` tests all days in March and October until the year 2100.
|
||||||
It was generated with `generateTimesMarchOctober.sh`. As the minutes and seconds are generated randomly a new testscript can show new erros.
|
It was generated with `generateTimesMarchOctober.sh`. As the minutes and seconds are generated randomly a new testscript can help to show new erros.
|
||||||
|
|
||||||
The file `testTimes.lua` tests all days from this year up to the year 2020.
|
The file `testTimes.lua` tests all days from this year up to the year 2020.
|
||||||
It was generated with `testTimes.lua`.
|
It was generated with `testTimes.lua`.
|
||||||
|
|
||||||
### UnixTimestamp to UTC convertion
|
### UnixTimestamp to UTC convertion
|
||||||
|
The file `testUnixtimes.lua` tests the convertion of an unixtimestamp (Second since 1970) to year, month, day, hour, minute, second and dayOfWeek.
|
||||||
|
It was generated with `generateUnixtimes.sh`. As the hour, minutes and seconds are generated randomly a new testscript can help to show new errors.
|
||||||
|
|
||||||
## UnixTimestamp to local time convertion
|
## UnixTimestamp to local time convertion
|
||||||
These tests combins both chaptes above.
|
These tests combins both chaptes above.
|
||||||
@ -22,4 +24,5 @@ The tests can be reproduced with the following commands:
|
|||||||
```
|
```
|
||||||
$ lua testTimesMarchOctober.lua
|
$ lua testTimesMarchOctober.lua
|
||||||
$ lua testTimes.lua
|
$ lua testTimes.lua
|
||||||
|
$ lua testUnixtimes.lua
|
||||||
```
|
```
|
||||||
|
@ -7,14 +7,23 @@
|
|||||||
#4
|
#4
|
||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
# Call this script and write the output of stdout into a file.
|
# Call this script and generate a new testUnixtime.lua
|
||||||
# e.g.: ./generateUnixtime.sh > unixtimetest.lua
|
# Run the test afterwards like the following:
|
||||||
|
# $ lua testUnixtime.lua
|
||||||
|
|
||||||
|
|
||||||
|
# remove the tailing "./" and the extension of this script
|
||||||
|
OUTPUT="$(echo "$0" | sed 's;^./;;' | cut -d'.' -f1).lua"
|
||||||
|
#rename OUTPUT from generate to test
|
||||||
|
OUTPUT="$(echo "$OUTPUT" | sed 's;generate;test;')"
|
||||||
|
|
||||||
|
echo "Generating $OUTPUT ..."
|
||||||
|
|
||||||
# Generate the header
|
# Generate the header
|
||||||
cat << EOF
|
cat << EOF > $OUTPUT
|
||||||
dofile("../timecore.lua")
|
dofile("../timecore.lua")
|
||||||
function checkUnixTime(resultYear, resultMonth, resultDay, resultHour, resultMinute, resultSecond, resultDow, unixtime)
|
function checkUnixTime(resultYear, resultMonth, resultDay, resultHour, resultMinute, resultSecond, resultDow, unixtime)
|
||||||
year, month, day, hour, minute, second, dow = gettime(unixtime)
|
year, month, day, hour, minute, second, dow = getUTCtime(unixtime)
|
||||||
|
|
||||||
if not (year == resultYear and resultMonth == month and day == resultDay and hour == resultHour and minute == resultMinute and second == resultSecond and dow == resultDow) then
|
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(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " day of week : " .. resultDow .. " not extracted from " .. unixtime)
|
||||||
@ -38,15 +47,24 @@ for year in {2016..2020}; do
|
|||||||
timestmp="$year-$month-$day $hour:$minutes:$seconds"
|
timestmp="$year-$month-$day $hour:$minutes:$seconds"
|
||||||
date -d "$timestmp" "+%F %T" >> /dev/null
|
date -d "$timestmp" "+%F %T" >> /dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "--Time $timestmp is not valid"
|
echo "--Time $timestmp is not valid" >> $OUTPUT
|
||||||
else
|
else
|
||||||
unixtime=$(date -u -d "$timestmp" '+%s')
|
unixtime=$(date -u -d "$timestmp" '+%s')
|
||||||
dayofweek=$(date -u -d "$timestmp" '+%w')
|
dayofweek=$(date -u -d "$timestmp" '+%w')
|
||||||
# Generate the lua test command, like: checkTime(2015, 1, 1, 10, 11, 12, 0, 1)
|
# 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)"
|
echo "checkUnixTime($year, $month, $day, $hour, $minutes, $seconds, $dayofweek, $unixtime)" >> $OUTPUT
|
||||||
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Generate the footer
|
||||||
|
cat << EOF >> $OUTPUT
|
||||||
|
print "Finished with all tests"
|
||||||
|
os.exit(0)
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "---------------------------"
|
||||||
|
echo "Usage:"
|
||||||
|
echo "Call >lua $OUTPUT< in the terminal to execute the test"
|
||||||
exit 0
|
exit 0
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user