comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Ada.Calendar.Formatting.Image (or Time_Of) changing the time
Date: Tue, 03 Mar 2020 14:53:43 +0000
Date: 2020-03-03T14:53:43+00:00	[thread overview]
Message-ID: <lyv9nl8p6w.fsf@pushface.org> (raw)
In-Reply-To: e92d8c8d-a182-4990-b3f6-33c2ab90bce9@googlegroups.com

Marius Amado-Alves <amado.alves@gmail.com> writes:

> Feeding Ada.Calendar.Formatting.Image with an Ada.Calendar.Time_Of the
> year, month, day, seconds on the left, we get the image on the
> right. Some images, marked *, are 1 hour behind.
>
> 2015 1 21 32040 ( 8:54 AM) => 2015-01-21 08:54:00
> 2015 1 21 39240 (10:54 AM) => 2015-01-21 10:54:00
> 2015 7 21 32040 ( 8:54 AM) => 2015-07-21 07:54:00 *
> 2015 7 21 39240 (10:54 AM) => 2015-07-21 09:54:00 *
>
> The different input is the month, January versus July, so it looks
> like a daylight savings thing. Is this expected behaviour? Thanks.
>
> [Compiler = GNAT Community 2018 (20180523-73)]

There was a conversation on Ada-Comment in June last year, in which it
turned out that compiler implementers may have have been misinterpreting
the ARM. It was quite confusing.

Part of the problem is that Ada.Calendar.Clock, implemented over the OS
facilities, may or may not be in local time; and how does it treat times
which are not in the 'now' time zone?

I wrote this:

   with Ada.Calendar.Formatting;
   with Ada.Calendar.Time_Zones;
   with Ada.Text_IO;
   procedure Marius is
      use type Ada.Calendar.Time;
      Earlier : constant Ada.Calendar.Time
        := Ada.Calendar.Time_Of (2015, 1, 21, 32040.0);
      Later : constant Ada.Calendar.Time
        := Ada.Calendar.Time_Of (2015, 7, 21, 32040.0);
      Offset_Earlier : constant Ada.Calendar.Time_Zones.Time_Offset
        := Ada.Calendar.Time_Zones.UTC_Time_Offset (Earlier);
      Offset_Later : constant Ada.Calendar.Time_Zones.Time_Offset
        := Ada.Calendar.Time_Zones.UTC_Time_Offset (Later);
   begin
      Ada.Text_Io.Put_Line ("Earlier");
      Ada.Text_IO.Put_Line
        ("UTC_Time_Offset: " & Offset_Earlier'Image);
      Ada.Text_IO.Put_Line
        ("Time_Zone default: "
           & Ada.Calendar.Formatting.Image (Earlier));
      Ada.Text_IO.Put_Line
        ("Time_Zone  offset: "
           & Ada.Calendar.Formatting.Image (Earlier, Time_Zone => Offset_Earlier));
      Ada.Text_IO.New_Line;
      Ada.Text_IO.Put_Line ("Later");
      Ada.Text_IO.Put_Line
        ("UTC_Time_Offset: " & Offset_Later'Image);
      Ada.Text_IO.Put_Line
        ("Time_Zone default: "
           & Ada.Calendar.Formatting.Image (Later));
      Ada.Text_IO.Put_Line
        ("Time_Zone  offset: "
           & Ada.Calendar.Formatting.Image (Later, Time_Zone => Offset_Later));
   end Marius;

and it appears that with GNAT (current free
versions), macOS Mojave, time zone London, Time_Of does something
mysterious;it seems that Time_Of looks at the time you specify (08:54)
and thinks to itself, "but the date part shows that's in DST, so the
local clock now (in GMT) would be reading 07:54"

   $ ./marius 
   Earlier
   UTC_Time_Offset:  0
   Time_Zone default: 2015-01-21 08:54:00
   Time_Zone  offset: 2015-01-21 08:54:00

   Later
   UTC_Time_Offset:  60
   Time_Zone default: 2015-07-21 07:54:00
   Time_Zone  offset: 2015-07-21 08:54:00

Just for fun, trying a different time zone (this may well NOT be the
same as actually being in that time zone :)

   $ TZ=EST ./marius 
   Earlier
   UTC_Time_Offset: -300
   Time_Zone default: 2015-01-21 13:54:00
   Time_Zone  offset: 2015-01-21 08:54:00

   Later
   UTC_Time_Offset: -300
   Time_Zone default: 2015-07-21 13:54:00
   Time_Zone  offset: 2015-07-21 08:54:00

Same results on Debian (running in a VM on this Macbook).


  parent reply	other threads:[~2020-03-03 14:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-02 18:49 Ada.Calendar.Formatting.Image (or Time_Of) changing the time Marius Amado-Alves
2020-03-02 23:08 ` Randy Brukardt
2020-03-03 12:59   ` Marius Amado-Alves
2020-03-03 14:25     ` Dmitry A. Kazakov
2020-03-03 14:53 ` Simon Wright [this message]
2020-03-03 17:40   ` Simon Wright
2020-03-03 23:49   ` Randy Brukardt
2020-03-04 15:19     ` Simon Wright
2020-03-04 22:33     ` Optikos
2020-03-05 16:11       ` Optikos
2020-03-05 23:29       ` Randy Brukardt
2020-03-06 14:42         ` Optikos
2020-03-07  0:19           ` Randy Brukardt
2020-03-07  1:18             ` Optikos
replies disabled

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