#!/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 2021-09-17 20:00:00.000 to 47 timestamps:

Active Directory/LDAP:		132763824000000000
Apple Biome 64-bit decimal:	4738766015976964096
Apple Biome hex time:		41c37a95a0000000
BitDate time:			008d597e
Bitwise Decimal time:		2119798016
DHCP6 DUID time:		0001000128d7b040000000000000
exFAT time:			5331a000
FAT Date + Time:		315300a0
GMail Boundary time:		00000000000054700005cc366000
GMail Message ID time:		17bf558260000000
Google Chrome:			13276382400000000
Google EI time:			wPNEYQ
GPS time:			1315944018
GSM time:			12907102000000
HFS/HFS+ 32-bit Hex BE:		dd6aa440
HFS/HFS+ 32-bit Hex LE:		40a46add
KSUID Decimal:			231908800
Mac OS/HFS+ Decimal Time:	3714753600
Mastodon time:			106948775116800000
Microsoft 128-bit SYSTEMTIME:	e5070900050011001400000000000000
Microsoft FILETIME time:	988ae000:01d7abfe
Microsoft Hotmail time:		feabd701:00e08a98
Microsoft .NET DateTime:	637675056000000000
Motorola time:			330911140000
Mozilla PRTime:			1631908800000000
MS-DOS 32-bit Hex Value:	00a03153
MS Excel 1904 Date:		42994.833333333336
Nokia S40 time:			07e50911140000
Nokia S40 time LE:		e5070911140000
Nokia time:			caca7dbf
Nokia time LE:			bf7dcaca
NSDate - Binary Plist / Cocoa:	653601600
NSDate - iOS 11+:		653601600000000000
NSDate - Mac Absolute time:	653601600.000000
OLE Automation Date:		44456.833333333336
S32 Encoded (Bluesky) time:		3jjupkdk2
Symantec AV time:		330811140000
Unix Hex 32-bit BE:		6144f3c0
Unix Hex 32-bit LE:		c0f34461
Unix Seconds:			1631908800
Unix Milliseconds:		1631908800000
VMSD time:			379958,1616146432
Windows 64-bit Hex BE:		01d7abfe988ae000
Windows 64-bit Hex LE:		00e08a98feabd701
Windows Cookie Date:		2559238144,30911486
Windows OLE 64-bit double BE:	40e5b51aaaaaaaab
Windows OLE 64-bit double LE:	abaaaaaa1ab5e540

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
