#!/bin/sh

# Stops the execution, if an error is encountered
set -e

# Defines expected results and removes blank lines as well as
# whitespace characters
EXPECTED=$(cat <<'EOF' | sed '/^$/d' | sed 's/\s//g' 


Converting Date: 2021-09-17 20:00:00.000

Unix Seconds:                   1631908800
Unix Milliseconds:              1631908800000
Windows 64-bit Hex BE:          01d7abfe988ae000
Windows 64-bit Hex LE:          00e08a98feabd701
Google Chrome:                  13276382400000000
Active Directory/LDAP dt:       132763824000000000
Unix Hex 32-bit BE:             6144f3c0
Unix Hex 32-bit LE:             c0f34461
Windows Cookie Date:            2559238144,30911486
Windows OLE 64-bit double BE:   40e5b51aaaaaaaab
Windows OLE 64-bit double LE:   abaaaaaa1ab5e540
Mac Absolute Time:              653601600
Mac OS/HFS+ Decimal Time:       3714753600
HFS/HFS+ 32-bit Hex BE:         dd6aa440
HFS/HFS+ 32-bit Hex LE:         40a46add
MS-DOS 32-bit Hex Value:        00a03153
FAT Date + Time:                315300a0
Microsoft 128-bit SYSTEMTIME:   e5070900050011001400000000000000
Microsoft FILETIME time:        988ae000:01d7abfe
Microsoft Hotmail time:         feabd701:00e08a98
Mozilla PRTime:                 1631908800000000
OLE Automation Date:            44456.833333333336
MS Excel 1904 Date:             42994.833333333336
iOS 11 Date:                    653601600000000000
Symantec AV time:               330811140000
GPS time:                       1315944018
Google EI time:                 wPNEYQ
iOS Binary Plist time:          653601600
GSM time:                       12907102000000
VMSD time:                      379958,1616146432

EOF
)

# Run time-decode to decode unix epoch in secs and millis, remove
# blank lines and whitespace
ACTUAL="$(time-decode --timestamp '2021-09-17 20:00:00.000' \
	| sed '/^$/d' | sed 's/\s//g')"


# Checks, if each expected line exists in the actual results
# This won't fail if additional timestamp formats are added in the
# future
echo "${EXPECTED}" |
    while read line
    do
	echo "${ACTUAL}" | grep -q "${line}"
    done

exit 0
