At 2020-12-16T11:35:12+1100, G. Branden Robinson wrote: > What do people think about a GROFF_USE_UTC environment variable that > causes troff to call gmtime() instead of localtime()?
Here's a straw-man implementation. As part of this I deleted a James Clark comment from 1992; any version of g++ that was "old" then is certainly unsupported now, but more importantly I don't understand what was idiomatically wrong with the statement as it was. Automatic type inference (through overloading of the "auto" keyword) was a much, much later development of C++. Perhaps a better C++ programmer than I can explain it to me. Anyway, the diff is attached and here is the patch in action. $ cat EXPERIMENTS/get_time.groff .af year 0000 .af mo 00 .af dy 00 .af hours 00 .af minutes 00 .af seconds 00 .tm \n[year]-\n[mo]-\n[dy] \n[hours]:\n[minutes]:\n[seconds] $ alias tg alias tg='./build/test-groff' $ GROFF_USE_UTC=1 tg EXPERIMENTS/get_time.groff 2020-12-16 00:55:03 $ GROFF_USE_UTC= tg EXPERIMENTS/get_time.groff 2020-12-16 00:55:06 $ tg EXPERIMENTS/get_time.groff 2020-12-16 11:55:09 Thoughts? Regards, Branden
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index a4360280..f96a1bc1 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -8168,8 +8168,13 @@ static void init_registers()
time_t
#endif /* not LONG_FOR_TIME_T */
t = current_time();
- // Use struct here to work around misfeature in old versions of g++.
- struct tm *tt = localtime(&t);
+ char *use_utc = getenv("GROFF_USE_UTC");
+ struct tm *tt = 0;
+ if (use_utc)
+ tt = gmtime(&t);
+ else
+ tt = localtime(&t);
+
set_number_reg("seconds", int(tt->tm_sec));
set_number_reg("minutes", int(tt->tm_min));
set_number_reg("hours", int(tt->tm_hour));
signature.asc
Description: PGP signature
