From: Charles Darcy <charlie@mullum.com.au>
Subject: Ada.Calendar."+" gives peculiar result (Gnat 3.13)
Date: Tue, 03 Jul 2001 23:29:57 -0400
Date: 2001-07-03T23:29:57-04:00 [thread overview]
Message-ID: <3B428DB5.89E1D528@mullum.com.au> (raw)
Hello,
I've been using the Ada.Calendar.Time type to represent dates in my
program, and have struck a problem.
Within a loop, I add (7 * Ada.Calendar.Day_Duration'Last) to an
Ada.Calendar.Time object, at the end of each iteration. I expected this
to advance the time by 1 week, and so it does initially. After a number
of loop iterations, however, the addition seems to advance the time by 1
week and 1 hour.
Below is code which demonstrates the problem:
declare
use Ada.Text_IO;
use Ada.Calendar;
The_Year : Year_Number;
The_Month : Month_Number;
The_Day : Day_Number;
The_Seconds : Day_Duration;
The_Date : Time := Time_Of (1995, 12, 2);
begin
for Count in 1 .. 100 loop
Put_Line ("");
Put_Line ("Iteration: " & Integer'Image (Count));
Split (The_Date, The_Year, The_Month, The_Day, The_Seconds);
Put_Line ("The_Date:");
Put_Line (" year: " & Year_Number'Image (The_Year));
Put_Line (" month: " & Month_Number'Image (The_Month));
Put_Line (" day: " & Day_Number'Image (The_Day));
Put_Line (" seconds: " & Day_Duration'Image (The_Seconds));
The_Date := The_Date + 7 * Ada.Calendar.Day_Duration'Last;
end loop;
end;
The output begins with ...
Iteration: 1
The_Date:
year: 1995
month: 12
day: 2
seconds: 0.000000000
Iteration: 2
The_Date:
year: 1995
month: 12
day: 9
seconds: 0.000000000
Iteration: 3
The_Date:
year: 1995
month: 12
day: 16
seconds: 0.000000000
... which is as I expected. However, later on ...
Iteration: 19
The_Date:
year: 1996
month: 4
day: 6
seconds: 0.000000000
Iteration: 20
The_Date:
year: 1996
month: 4
day: 13
seconds: 3600.000000000
Iteration: 21
The_Date:
year: 1996
month: 4
day: 20
seconds: 3600.000000000
... an additional hour (the 3600 seconds) seems to have been added.
Still later, the additional hour disappears ...
Iteration: 48
The_Date:
year: 1996
month: 10
day: 26
seconds: 3600.000000000
Iteration: 49
The_Date:
year: 1996
month: 11
day: 2
seconds: 0.000000000
Iteration: 50
The_Date:
year: 1996
month: 11
day: 9
seconds: 0.000000000
Any ideas as to what is going on ? In case its relevant, I'm using Gnat
3.13p under Linux.
regards,
Charles.
P.S. Can anyone recommend a good Date package ?
next reply other threads:[~2001-07-04 3:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-04 3:29 Charles Darcy [this message]
2001-07-03 13:42 ` Ada.Calendar."+" gives peculiar result (Gnat 3.13) Ian Wild
2001-07-04 1:16 ` Charles Darcy
2001-07-03 13:49 ` Karel Thönissen
2001-07-04 4:00 ` Charles Darcy
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox