Skip to content

Commit 12abe14

Browse files
committed
tests: add interactive time conversion tryouts
1 parent 87750f1 commit 12abe14

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tests/utiltest.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <climits>
66
#include <cstdio>
77
#include <cstdlib>
8+
#include <ctime>
89
#include <limits>
910
#include <libHX/endian.h>
1011
#include <libHX/string.h>
@@ -600,7 +601,7 @@ static int runner()
600601
return EXIT_SUCCESS;
601602
}
602603

603-
int main()
604+
int main(int argc, char **argv)
604605
{
605606
static_assert(sizeof(cpu_to_le16(0)) == sizeof(uint16_t));
606607
static_assert(sizeof(cpu_to_le32(0)) == sizeof(uint32_t));
@@ -614,6 +615,25 @@ int main()
614615
static_assert(sizeof(be16_to_cpu(0)) == sizeof(uint16_t));
615616
static_assert(sizeof(be32_to_cpu(0)) == sizeof(uint32_t));
616617
static_assert(sizeof(be64_to_cpu(0)) == sizeof(uint64_t));
618+
if (argc >= 3 && strcmp(argv[1], "nttime") == 0) {
619+
auto nt = strtoll(argv[2], nullptr, 0);
620+
auto ut = rop_util_nttime_to_unix(nt);
621+
printf("...is unixtime %lld\n", static_cast<long long>(ut));
622+
char buf[64];
623+
auto tm = localtime(&ut);
624+
strftime(buf, std::size(buf), "%FT%T", tm);
625+
printf("...is calendar %s\n", buf);
626+
return EXIT_SUCCESS;
627+
} else if (argc >= 3 && strcmp(argv[1], "unixtime") == 0) {
628+
time_t ut = strtoll(argv[2], nullptr, 0);
629+
auto nt = rop_util_unix_to_nttime(ut);
630+
printf("...is nttime %lld\n", static_cast<long long>(nt));
631+
char buf[64];
632+
auto tm = localtime(&ut);
633+
strftime(buf, std::size(buf), "%FT%T", tm);
634+
printf("...is calendar %s\n", buf);
635+
return EXIT_SUCCESS;
636+
}
617637
auto ret = runner();
618638
if (ret != EXIT_SUCCESS)
619639
printf("FAILED\n");

0 commit comments

Comments
 (0)