groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to make groff use local timezone?


From: Steffen Nurpmeso
Subject: Re: How to make groff use local timezone?
Date: Mon, 14 Dec 2020 22:45:30 +0100
User-agent: s-nail v14.9.20-84-g7268a84d

Colin Watson wrote in
 <20201214154336.GA32542@riva.ucam.org>:
 |On Mon, Dec 14, 2020 at 02:12:28PM +1100, G. Branden Robinson wrote:
 |> At 2020-12-12T21:19:38-0800, Jim Avera wrote:
 |>> I suspect groff is always in UTC (but haven't confirmed).  
 |> 
 |> No, that is not true, at least not in groff as provided by GNU.  A
 |> downstream distributor, like a GNU/Linux distribution, could alter this.
 |
 |Debian currently does
 |(https://salsa.debian.org/debian/groff/blob/master/debian/patches/displa\
 |y-utc-times.patch).
 |But I'm unsure about the correctness of this, which is why I hadn't
 |pushed it upstream; it was something of a desperation measure to get
 |reproducible builds working in more places, but changing the semantics
 |of things like \n[hours] is not ideal.
 |
 |Perhaps playing whack-a-mole with TZ=UTC in more places would be better
 |in this case, although it seems unlikely to be much fun - I'm not sure.

My brute simple Web42 website "manager" offers UTC and LOCAL,
because it seemed good to offer both versions.  (The latter is
optional and equals the former unless some perl module is
installed that is so by default for a long time.)

When i mean is, isn't this a nice feature request, new number
registers named xy_utc or so?
I have not even tried all this, but it could be as simple as

  diff --git a/src/troff/input.cpp b/src/troff/input.cpp
  index f1714c51..559efe40 100644
  --- a/src/troff/input.cpp
  +++ b/src/troff/input.cpp
  @@ -7665,8 +7665,23 @@ static void init_registers()
     time_t
   #endif /* not LONG_FOR_TIME_T */
       t = time(0);
  +
     // Use struct here to work around misfeature in old versions of g++.
  -  struct tm *tt = localtime(&t);
  +  struct tm *tt;
  +
  +  while((tt = gmtime(&t)) == NULL)
  +    t = 0;
  +  set_number_reg("seconds_utc", int(tt->tm_sec));
  +  set_number_reg("minutes_utc", int(tt->tm_min));
  +  set_number_reg("hours_utc", int(tt->tm_hour));
  +  set_number_reg("dw_utc", int(tt->tm_wday + 1));
  +  set_number_reg("dy_utc", int(tt->tm_mday));
  +  set_number_reg("mo_utc", int(tt->tm_mon + 1));
  +  set_number_reg("year_utc", int(1900 + tt->tm_year));
  +  set_number_reg("yr_utc", int(tt->tm_year));
  +
  +  while((tt = localtime(&t)) == NULL)
  +    t = 0;
     set_number_reg("seconds", int(tt->tm_sec));
     set_number_reg("minutes", int(tt->tm_min));
     set_number_reg("hours", int(tt->tm_hour));

A bit ugly, but .. hmm.

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]