comp.lang.ada
 help / color / mirror / Atom feed
From: Bob Goddard <1963bib@googlemail.com>
Subject: Re: Getting the 3 letter time zone abbreviation
Date: Sat, 2 May 2020 05:46:41 -0700 (PDT)
Date: 2020-05-02T05:46:41-07:00	[thread overview]
Message-ID: <f52d4d39-757e-46e0-af0b-27d9aedc5ed4@googlegroups.com> (raw)
In-Reply-To: <r8feu5$1o0b$1@gioia.aioe.org>

Here goes...

On Linux and the various BSD's, the tm structure has been extended to include:

  long int tm_gmtoff;           /* Seconds east of UTC.  */
  const char *tm_zone;          /* Timezone abbreviation.  */

When you make a call to localtime_r, these are filled in with the correct into, at least on Linux.

The other big iron Unix's do not have this extension, and neither does Windows.

Windows also does not have localtime_r, instead it has localtime_s plus its 32 & 64 versions.

On the other Unix's & Windows, a call made to tzset (_tzset on Windows), which fills in tzname (_tzname under Windows). This should contain 2 record for non-saving & saving timezone name. and the correct entry can be garnered by way of tm_isdst.

To set another timezone, external var TZ should be set.

And don't test an example time of 1234 seconds past epoch for the UK expecting GMT. The UK was in fact in daylight saving time and double time (I think) for a few years. In my defence, I was only about 7yo and totally forgot about it.

There, clear as mud.

This works on Linux, the tm_zone is filled in by the call automatically...


with System;
with Interfaces;
with Interfaces.C;
with Interfaces.C.Strings;

package Unix is
   type tm is record
      tm_sec    : Interfaces.C.int;
      tm_min    : Interfaces.C.int;
      tm_hour   : Interfaces.C.int;
      tm_day    : Interfaces.C.int;
      tm_mon    : Interfaces.C.int;
      tm_year   : Interfaces.C.int;
      tm_wday   : Interfaces.C.int;
      tm_yday   : Interfaces.C.int;
      tm_isdst  : Interfaces.C.int;
      tm_gmtoff : Interfaces.C.long;
      tm_zone   : Interfaces.C.Strings.chars_ptr;
   end record;
   pragma Convention (C_Pass_By_Copy, tm);
   
   procedure localtime_r (T : System.Address; TM_Struct : System.Address);
   pragma Import (C, localtime_r, "localtime_r");
end Unix;

  reply	other threads:[~2020-05-02 12:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-29  8:46 Getting the 3 letter time zone abbreviation Bob Goddard
2020-04-29  9:09 ` Dmitry A. Kazakov
2020-04-29 19:20   ` Bob Goddard
2020-04-29 19:53     ` Dmitry A. Kazakov
2020-04-30 18:59       ` Bob Goddard
2020-04-30 21:11         ` Dmitry A. Kazakov
2020-05-02 12:46           ` Bob Goddard [this message]
2020-05-02 15:08             ` Bob Goddard
2020-05-02 15:38               ` Dmitry A. Kazakov
2020-05-02 19:25                 ` Bob Goddard
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox