From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.5toSSCP5H8WhQPVIfFrwuA.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Getting the 3 letter time zone abbreviation Date: Thu, 30 Apr 2020 23:11:34 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <4f7d162e-356c-4cc4-abc3-f4cfe195b9cd@googlegroups.com> <9dad342a-7981-4d09-a414-7cec651097ac@googlegroups.com> NNTP-Posting-Host: 5toSSCP5H8WhQPVIfFrwuA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:58534 Date: 2020-04-30T23:11:34+02:00 List-Id: On 2020-04-30 20:59, Bob Goddard wrote: > On Wednesday, 29 April 2020 20:53:11 UTC+1, Dmitry A. Kazakov wrote: >> On 2020-04-29 21:20, Bob Goddard wrote: >> >>> Seems easier just to import strftime and call it requesting just "%Z". This is on Linux, but MS suggests it should also work on Windows. >> >> An interesting idea. Did you try it under Windows? (There is a >> suspicious remark that it depends on the setlocale) > > 'Fraid not, I'm a Linux user. I just noticed that Windows does have it. OK, I tested it. As expected it does not work. For example this one: --------------------------- with Ada.Command_Line; use Ada.Command_Line; with Interfaces.C; use Interfaces.C; with Ada.Exceptions; use Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; with System; procedure Strftime_Test is type tm is record tm_sec : int; tm_min : int; tm_hour : int; tm_mday : int; tm_mon : int; tm_year : int; tm_wday : int; tm_yday : int; tm_isdst : int; end record; pragma Convention (C, tm); type tm_Ptr is access all tm; pragma Convention (C, tm_Ptr); type time_t is new Interfaces.Unsigned_64; function localtime (timep : access time_t) return tm_Ptr; pragma Import (C, localtime); function time (destTime : System.Address := System.Null_Address) return time_t; pragma Import (C, time, "_time64"); function strftime ( strDest : char_array; maxsize : size_t; format : char_array; timeptr : access tm ) return size_t; pragma Import (C, strftime); Result : size_t; Buffer : char_array (1..200); Now : aliased time_t := 0; Local_Ptr : tm_Ptr; begin Now := time; Put_Line ("Time=" & time_t'Image (Now)); Local_Ptr := localtime (Now'Access); if Local_Ptr /= null then declare Local : tm renames localtime (Now'Access).all; begin Put_Line ( int'Image (Local.tm_year) & " -" & int'Image (Local.tm_mon) & " -" & int'Image (Local.tm_mday) & " " & int'Image (Local.tm_hour) & " :" & int'Image (Local.tm_min) & " :" & int'Image (Local.tm_sec) ); Result := strftime ( Buffer, Buffer'Length, To_C ("%#Z"), Local'Access ); Put_Line ("Result=" & To_Ada (Buffer (1..Result), False)); end; end if; Set_Exit_Status (0); exception when Error : Status_Error | Data_Error => Put_Line (Exception_Message (Error)); Set_Exit_Status (1); when Error : others => Put_Line ("Fault: " & Exception_Information (Error)); Set_Exit_Status (2); end Strftime_Test; ---------------------------------- Gives the output on my Windows machine: Result=W. Europe Daylight Time instead of CEST Windows POSIX layer relies on Windows API. If the API does something wrong, so would whatever POSIX function. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de