* Re: Windows file timestamp converted to local time
[not found] <262bea8c-57ff-480e-b5aa-da94f0436e98n@googlegroups.com>
@ 2023-10-16 18:35 ` Matt Borchers
2023-10-16 18:49 ` Niklas Holsti
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Matt Borchers @ 2023-10-16 18:35 UTC (permalink / raw)
Below is the function from System.OS_Lib.
Does anybody know where the C implementation can be found?
Does anybody know where the C implementation of "localtime" is found?
function File_Time_Stamp (Name : C_File_Name) return OS_Time is
function File_Time (Name : Address) return OS_Time;
pragma Import (C, File_Time, "__gnat_file_time_name");
begin
return File_Time (Name);
end File_Time_Stamp;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Windows file timestamp converted to local time
2023-10-16 18:35 ` Windows file timestamp converted to local time Matt Borchers
@ 2023-10-16 18:49 ` Niklas Holsti
2023-10-17 2:39 ` Randy Brukardt
2023-10-17 14:13 ` Matt Borchers
2023-10-16 19:14 ` Simon Wright
2023-10-17 7:25 ` Dmitry A. Kazakov
2 siblings, 2 replies; 8+ messages in thread
From: Niklas Holsti @ 2023-10-16 18:49 UTC (permalink / raw)
On 2023-10-16 21:35, Matt Borchers wrote:
> Below is the function from System.OS_Lib.
> Does anybody know where the C implementation can be found?
> Does anybody know where the C implementation of "localtime" is found?
>
> function File_Time_Stamp (Name : C_File_Name) return OS_Time is
> function File_Time (Name : Address) return OS_Time;
> pragma Import (C, File_Time, "__gnat_file_time_name");
> begin
> return File_Time (Name);
> end File_Time_Stamp;
(This question seems to be a follow-up ("Re:") to some earlier post, but
my newsreader does not seem to find or show that earlier post.)
What is the problem?
Have you tried using the standard Ada services:
Ada.Directories.Modification_Time and
Ada.Calendar.Time_Zones.Local_Time_Offset?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Windows file timestamp converted to local time
2023-10-16 18:35 ` Windows file timestamp converted to local time Matt Borchers
2023-10-16 18:49 ` Niklas Holsti
@ 2023-10-16 19:14 ` Simon Wright
2023-10-17 7:25 ` Dmitry A. Kazakov
2 siblings, 0 replies; 8+ messages in thread
From: Simon Wright @ 2023-10-16 19:14 UTC (permalink / raw)
Matt Borchers <mattborchers@gmail.com> writes:
> Below is the function from System.OS_Lib.
> Does anybody know where the C implementation can be found?
> Does anybody know where the C implementation of "localtime" is found?
>
> function File_Time_Stamp (Name : C_File_Name) return OS_Time is
> function File_Time (Name : Address) return OS_Time;
> pragma Import (C, File_Time, "__gnat_file_time_name");
> begin
> return File_Time (Name);
> end File_Time_Stamp;
For the first question, very likely to be in gcc/ada/adaint.c in the GCC
sources (https://github.com/gcc-mirror/gcc)
localtime() is in libc; depends on your OS.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Windows file timestamp converted to local time
2023-10-16 18:49 ` Niklas Holsti
@ 2023-10-17 2:39 ` Randy Brukardt
2023-10-17 14:13 ` Matt Borchers
1 sibling, 0 replies; 8+ messages in thread
From: Randy Brukardt @ 2023-10-17 2:39 UTC (permalink / raw)
"Niklas Holsti" <niklas.holsti@tidorum.invalid> wrote in message
news:kp5eucFogqpU1@mid.individual.net...
> On 2023-10-16 21:35, Matt Borchers wrote:
>> Below is the function from System.OS_Lib.
>> Does anybody know where the C implementation can be found?
>> Does anybody know where the C implementation of "localtime" is found?
>>
>> function File_Time_Stamp (Name : C_File_Name) return OS_Time is
>> function File_Time (Name : Address) return OS_Time;
>> pragma Import (C, File_Time, "__gnat_file_time_name");
>> begin
>> return File_Time (Name);
>> end File_Time_Stamp;
>
>
> (This question seems to be a follow-up ("Re:") to some earlier post, but
> my newsreader does not seem to find or show that earlier post.)
>
> What is the problem?
>
> Have you tried using the standard Ada services:
> Ada.Directories.Modification_Time and
> Ada.Calendar.Time_Zones.Local_Time_Offset?
...as those will work on (almost) any target system, while the actual
implementation is going to be rather OS-dependent. And there never is a good
reason to use a GNAT-only (or any compiler-specific, for any compiler)
facility when there is an equivalent standard facility. Most of those
facilities pre-date the Ada ones.
Randy.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Windows file timestamp converted to local time
2023-10-16 18:35 ` Windows file timestamp converted to local time Matt Borchers
2023-10-16 18:49 ` Niklas Holsti
2023-10-16 19:14 ` Simon Wright
@ 2023-10-17 7:25 ` Dmitry A. Kazakov
2 siblings, 0 replies; 8+ messages in thread
From: Dmitry A. Kazakov @ 2023-10-17 7:25 UTC (permalink / raw)
On 2023-10-16 20:35, Matt Borchers wrote:
> Below is the function from System.OS_Lib.
> Does anybody know where the C implementation can be found?
> Does anybody know where the C implementation of "localtime" is found?
>
> function File_Time_Stamp (Name : C_File_Name) return OS_Time is
> function File_Time (Name : Address) return OS_Time;
> pragma Import (C, File_Time, "__gnat_file_time_name");
> begin
> return File_Time (Name);
> end File_Time_Stamp;
If I correctly interpret the description, OS_Time is FILETIME under
Windows, i.e. 64-bit value.
https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime
As for implementation it likely calls to GetFileTime after obtaining a
handle to the file.
https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfiletime
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Windows file timestamp converted to local time
2023-10-16 18:49 ` Niklas Holsti
2023-10-17 2:39 ` Randy Brukardt
@ 2023-10-17 14:13 ` Matt Borchers
2023-10-17 16:28 ` Niklas Holsti
1 sibling, 1 reply; 8+ messages in thread
From: Matt Borchers @ 2023-10-17 14:13 UTC (permalink / raw)
On Monday, October 16, 2023 at 2:49:52 PM UTC-4, Niklas Holsti wrote:
> On 2023-10-16 21:35, Matt Borchers wrote:
> > Below is the function from System.OS_Lib.
> > Does anybody know where the C implementation can be found?
> > Does anybody know where the C implementation of "localtime" is found?
> >
> > function File_Time_Stamp (Name : C_File_Name) return OS_Time is
> > function File_Time (Name : Address) return OS_Time;
> > pragma Import (C, File_Time, "__gnat_file_time_name");
> > begin
> > return File_Time (Name);
> > end File_Time_Stamp;
> (This question seems to be a follow-up ("Re:") to some earlier post, but
> my newsreader does not seem to find or show that earlier post.)
>
> What is the problem?
>
> Have you tried using the standard Ada services:
> Ada.Directories.Modification_Time and
> Ada.Calendar.Time_Zones.Local_Time_Offset?
Thank you for the suggestion of using "Ada.Directories.Modification_Time". I didn't think to look in that package. This function adjusts for daylight savings time and returns the time as displayed in Windows Explorer.
There needs to be better comments (and documentation) for these time related functions. It is often not clear what time is returned. It is safe to assume UTC or local time, but the daylight savings issue caused confusion.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Windows file timestamp converted to local time
2023-10-17 14:13 ` Matt Borchers
@ 2023-10-17 16:28 ` Niklas Holsti
2023-10-17 16:35 ` Simon Wright
0 siblings, 1 reply; 8+ messages in thread
From: Niklas Holsti @ 2023-10-17 16:28 UTC (permalink / raw)
On 2023-10-17 17:13, Matt Borchers wrote:
> On Monday, October 16, 2023 at 2:49:52 PM UTC-4, Niklas Holsti wrote:
>> On 2023-10-16 21:35, Matt Borchers wrote:
>>> Below is the function from System.OS_Lib.
>>> Does anybody know where the C implementation can be found?
>>> Does anybody know where the C implementation of "localtime" is found?
>>>
>>> function File_Time_Stamp (Name : C_File_Name) return OS_Time is
>>> function File_Time (Name : Address) return OS_Time;
>>> pragma Import (C, File_Time, "__gnat_file_time_name");
>>> begin
>>> return File_Time (Name);
>>> end File_Time_Stamp;
>> (This question seems to be a follow-up ("Re:") to some earlier post, but
>> my newsreader does not seem to find or show that earlier post.)
>>
>> What is the problem?
>>
>> Have you tried using the standard Ada services:
>> Ada.Directories.Modification_Time and
>> Ada.Calendar.Time_Zones.Local_Time_Offset?
>
> Thank you for the suggestion of using "Ada.Directories.Modification_Time".
Happy to help!
> I didn't think to look in that package.
Ada.Directories does, IMO, seem the best place for it, since it should
not depend on the type of the file -- text, sequential, etc.
> This function adjusts for daylight savings time and returns the time
> as displayed in Windows Explorer.
>
> There needs to be better comments (and documentation) for these time
> related functions. It is often not clear what time is returned.
Yes, but some of that documentation should not be in the Ada standard,
but in the compiler's documentation.
Ada.Directories.Modification_Time returns a value of type
Ada.Calendar.Time. However, "the time base associated with the type Time
of package Calendar is implementation defined" (RM 9.6(23)) so it should
be documented in the implementation documents, that is in the GNAT
documentation. Have you looked there?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Windows file timestamp converted to local time
2023-10-17 16:28 ` Niklas Holsti
@ 2023-10-17 16:35 ` Simon Wright
0 siblings, 0 replies; 8+ messages in thread
From: Simon Wright @ 2023-10-17 16:35 UTC (permalink / raw)
Niklas Holsti <niklas.holsti@tidorum.invalid> writes:
> Ada.Directories.Modification_Time returns a value of type
> Ada.Calendar.Time. However, "the time base associated with the type
> Time of package Calendar is implementation defined" (RM 9.6(23)) so it
> should be documented in the implementation documents, that is in the
> GNAT documentation. Have you looked there?
The GNAT RM says in Implementation Defined Characteristics[1]
"The time base used is that provided by the C library function gettimeofday."
[1] https://docs.adacore.com/live/wave/gnat_rm/html/gnat_rm/gnat_rm/implementation_defined_characteristics.html
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-10-17 16:35 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <262bea8c-57ff-480e-b5aa-da94f0436e98n@googlegroups.com>
2023-10-16 18:35 ` Windows file timestamp converted to local time Matt Borchers
2023-10-16 18:49 ` Niklas Holsti
2023-10-17 2:39 ` Randy Brukardt
2023-10-17 14:13 ` Matt Borchers
2023-10-17 16:28 ` Niklas Holsti
2023-10-17 16:35 ` Simon Wright
2023-10-16 19:14 ` Simon Wright
2023-10-17 7:25 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox