comp.lang.ada
 help / color / mirror / Atom feed
* Getting current date and time
@ 2007-07-22 21:21 Maciej Sobczak
  2007-07-22 23:00 ` Martin
  2007-07-23 19:26 ` Gautier
  0 siblings, 2 replies; 17+ messages in thread
From: Maciej Sobczak @ 2007-07-22 21:21 UTC (permalink / raw)


It looks like there is no standard package for handling current time
and date and operations of these entities.

What are the available solutions?

--
Maciej Sobczak
http://www.msobczak.com/




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-22 21:21 Getting current date and time Maciej Sobczak
@ 2007-07-22 23:00 ` Martin
  2007-07-23 15:24   ` koburtch
  2007-07-23 19:57   ` Maciej Sobczak
  2007-07-23 19:26 ` Gautier
  1 sibling, 2 replies; 17+ messages in thread
From: Martin @ 2007-07-22 23:00 UTC (permalink / raw)


On 22 Jul, 22:21, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
> It looks like there is no standard package for handling current time
> and date and operations of these entities.
>
> What are the available solutions?
>
> --
> Maciej Sobczakhttp://www.msobczak.com/

Ada.Calendar

or if you have an Ada2005 compiler

Ada.Calendar + Ada.Calendar.Arithmetic, Ada.Calendar.Formatting and
Ada.Calendar.Time_Zones

Cheers
-- Martin





^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-22 23:00 ` Martin
@ 2007-07-23 15:24   ` koburtch
  2007-07-23 19:57   ` Maciej Sobczak
  1 sibling, 0 replies; 17+ messages in thread
From: koburtch @ 2007-07-23 15:24 UTC (permalink / raw)


On Jul 22, 7:00 pm, Martin <martin.do...@btopenworld.com> wrote:
> On 22 Jul, 22:21, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
>
> > It looks like there is no standard package for handling current time
> > and date and operations of these entities.
>
> > What are the available solutions?
>
> > --
> > Maciej Sobczakhttp://www.msobczak.com/
>
> Ada.Calendar
>
> or if you have an Ada2005 compiler
>
> Ada.Calendar + Ada.Calendar.Arithmetic, Ada.Calendar.Formatting and
> Ada.Calendar.Time_Zones
>
> Cheers
> -- Martin

You can see an example in my Big Online Book of Linux Ada Programming
at http://www.pegasoft.ca/boblap.html in Section 12.6.

Ken B.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-22 21:21 Getting current date and time Maciej Sobczak
  2007-07-22 23:00 ` Martin
@ 2007-07-23 19:26 ` Gautier
  1 sibling, 0 replies; 17+ messages in thread
From: Gautier @ 2007-07-23 19:26 UTC (permalink / raw)


Maciej Sobczak wrote:
> It looks like there is no standard package for handling current time
> and date and operations of these entities.

No only there is a standard package (see Martin's answer), but it is even 
there from the very first version of Ada (1983)! Then it was Calendar, already 
with nice overloaded operators (time - time -> duration, time + duration -> 
time, etc.) and other useful functions.
http://archive.adaic.com/standards/83lrm/html/lrm-09-06.html
It seems tat Ada.Calendar (95, 2005) just adds the "Ada.".
______________________________________________________________
Gautier         -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-22 23:00 ` Martin
  2007-07-23 15:24   ` koburtch
@ 2007-07-23 19:57   ` Maciej Sobczak
  2007-07-23 20:02     ` Maciej Sobczak
  1 sibling, 1 reply; 17+ messages in thread
From: Maciej Sobczak @ 2007-07-23 19:57 UTC (permalink / raw)


On 23 Lip, 01:00, Martin <martin.do...@btopenworld.com> wrote:

> Ada.Calendar

http://www.adaic.org/standards/05aarm/html/AA-TOC.html

Am I missing something by not being able to find it on this page?

I remember that Barnes mentions Ada.Calendar in his book, but I used
the above table of contents to locate standard packages. Ada.Calendard
does not seem to be on the list. Why?

--
Maciej Sobczak
http://www.msobczak.com/




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-23 19:57   ` Maciej Sobczak
@ 2007-07-23 20:02     ` Maciej Sobczak
  2007-07-23 20:08       ` Maciej Sobczak
  2007-07-23 21:39       ` Adam Beneschan
  0 siblings, 2 replies; 17+ messages in thread
From: Maciej Sobczak @ 2007-07-23 20:02 UTC (permalink / raw)


On 23 Lip, 21:57, Maciej Sobczak <see.my.homep...@gmail.com> wrote:

> > Ada.Calendar
>
> http://www.adaic.org/standards/05aarm/html/AA-TOC.html
>
> Am I missing something by not being able to find it on this page?

I've found it now in the Index - it is described in section 9.6, which
is not part of the standard library description.

--
Maciej Sobczak
http://www.msobczak.com/




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-23 20:02     ` Maciej Sobczak
@ 2007-07-23 20:08       ` Maciej Sobczak
  2007-07-23 21:43         ` Adam Beneschan
  2007-08-01  9:45         ` Jacob Sparre Andersen
  2007-07-23 21:39       ` Adam Beneschan
  1 sibling, 2 replies; 17+ messages in thread
From: Maciej Sobczak @ 2007-07-23 20:08 UTC (permalink / raw)


On 23 Lip, 22:02, Maciej Sobczak <see.my.homep...@gmail.com> wrote:

> I've found it now in the Index - it is described in section 9.6, which
> is not part of the standard library description.

Still, I don't know how to portably get the number of seconds in the
Unix epoch (for example, now is 1185221230). The built-in Duration
type is not guaranteed to have the necessary range.
How to solve it?

--
Maciej Sobczak
http://www.msobczak.com/




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-23 20:02     ` Maciej Sobczak
  2007-07-23 20:08       ` Maciej Sobczak
@ 2007-07-23 21:39       ` Adam Beneschan
  1 sibling, 0 replies; 17+ messages in thread
From: Adam Beneschan @ 2007-07-23 21:39 UTC (permalink / raw)


On Jul 23, 1:02 pm, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
> On 23 Lip, 21:57, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
>
> > > Ada.Calendar
>
> >http://www.adaic.org/standards/05aarm/html/AA-TOC.html
>
> > Am I missing something by not being able to find it on this page?
>
> I've found it now in the Index - it is described in section 9.6, which
> is not part of the standard library description.

The first page of Annex A lists all the packages in the standard
library, along with the RM reference where each package is defined.
Ada.Calendar is there.  They're not all defined in the annexes; some
of the packages are defined in chapters 3, 7, 9, 11, and 13.  Other
than that list, I don't think there is a particular section of the
manual that is called "the standard library description".

                         -- Adam




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-23 20:08       ` Maciej Sobczak
@ 2007-07-23 21:43         ` Adam Beneschan
  2007-07-24  8:53           ` Maciej Sobczak
  2007-08-01  9:45         ` Jacob Sparre Andersen
  1 sibling, 1 reply; 17+ messages in thread
From: Adam Beneschan @ 2007-07-23 21:43 UTC (permalink / raw)


On Jul 23, 1:08 pm, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
> On 23 Lip, 22:02, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
>
> > I've found it now in the Index - it is described in section 9.6, which
> > is not part of the standard library description.
>
> Still, I don't know how to portably get the number of seconds in the
> Unix epoch (for example, now is 1185221230). The built-in Duration
> type is not guaranteed to have the necessary range.
> How to solve it?

In Ada 2005, this is handled by the Differences procedure in
Ada.Calendar.Arithmetic (9.6.1).  You can use Ada.Calendar.Time_Of to
create the Time value for January 1, 1970, and then use that as a
parameter to Differences.

                     -- Adam





^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-23 21:43         ` Adam Beneschan
@ 2007-07-24  8:53           ` Maciej Sobczak
  2007-07-24  9:41             ` Georg Bauhaus
                               ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Maciej Sobczak @ 2007-07-24  8:53 UTC (permalink / raw)


On 23 Lip, 23:43, Adam Beneschan <a...@irvine.com> wrote:

> In Ada 2005, this is handled by the Differences procedure in
> Ada.Calendar.Arithmetic (9.6.1).  You can use Ada.Calendar.Time_Of to
> create the Time value for January 1, 1970, and then use that as a
> parameter to Differences.

The problem is that I need just a number of seconds (this is for
interfacing with other software which uses that Unix-like time
descriptions), so I cannot use the value which is broken down into
several components.
Moreover, the concept of leap seconds does not fit here neither (or
does it?).

Try this on GNU/Linux:

$ date +%s

I need to get the same number at the time the program is executed.

--
Maciej Sobczak
http://www.msobczak.com/




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-24  8:53           ` Maciej Sobczak
@ 2007-07-24  9:41             ` Georg Bauhaus
  2007-07-24  9:58               ` Maciej Sobczak
  2007-07-24 15:24             ` Adam Beneschan
  2007-07-28  8:20             ` Wilhelm Spickermann
  2 siblings, 1 reply; 17+ messages in thread
From: Georg Bauhaus @ 2007-07-24  9:41 UTC (permalink / raw)


On Tue, 2007-07-24 at 01:53 -0700, Maciej Sobczak wrote:
> On 23 Lip, 23:43, Adam Beneschan <a...@irvine.com> wrote:
> 
> > In Ada 2005, this is handled by the Differences procedure in
> > Ada.Calendar.Arithmetic (9.6.1).  You can use Ada.Calendar.Time_Of to
> > create the Time value for January 1, 1970, and then use that as a
> > parameter to Differences.
> 
> The problem is that I need just a number of seconds (this is for
> interfacing with other software which uses that Unix-like time
> descriptions), so I cannot use the value which is broken down into
> several components.
> Moreover, the concept of leap seconds does not fit here neither (or
> does it?).

If recomputing the seconds doesn't seem adequate,
and you want Unix epoch seconds, why not call the
system function that provides Unix epoch seconds?





^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-24  9:41             ` Georg Bauhaus
@ 2007-07-24  9:58               ` Maciej Sobczak
  0 siblings, 0 replies; 17+ messages in thread
From: Maciej Sobczak @ 2007-07-24  9:58 UTC (permalink / raw)


On 24 Lip, 11:41, Georg Bauhaus <rm.tsoh+bauh...@maps.futureapps.de>
wrote:

> If recomputing the seconds doesn't seem adequate,
> and you want Unix epoch seconds, why not call the
> system function that provides Unix epoch seconds?

This can break portability (not that I'm actually very much interested
in preserving it).

It looks like this is the most adequate approach here.

--
Maciej Sobczak
http://www.msobczak.com/




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-24  8:53           ` Maciej Sobczak
  2007-07-24  9:41             ` Georg Bauhaus
@ 2007-07-24 15:24             ` Adam Beneschan
  2007-07-25  7:26               ` Maciej Sobczak
  2007-07-28  8:20             ` Wilhelm Spickermann
  2 siblings, 1 reply; 17+ messages in thread
From: Adam Beneschan @ 2007-07-24 15:24 UTC (permalink / raw)


On Jul 24, 1:53 am, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
> On 23 Lip, 23:43, Adam Beneschan <a...@irvine.com> wrote:
>
> > In Ada 2005, this is handled by the Differences procedure in
> > Ada.Calendar.Arithmetic (9.6.1).  You can use Ada.Calendar.Time_Of to
> > create the Time value for January 1, 1970, and then use that as a
> > parameter to Differences.
>
> The problem is that I need just a number of seconds (this is for
> interfacing with other software which uses that Unix-like time
> descriptions), so I cannot use the value which is broken down into
> several components.

Why not?  Differences returns the result in "days" and "seconds", and
you should be able to convert the "days" to seconds by multiplying it
by a value that I just recently helped my 9-year-old figure out, and
then adding the result to the second value, and then maybe adding the
leap seconds (see below).

> Moreover, the concept of leap seconds does not fit here neither (or
> does it?).

Your previous post said that the purpose was to "interfac[e] with
other software which uses that Unix-like time descriptions".  I don't
think we can answer anything else without knowing just what that other
software does.  If the other software uses seconds since January 1,
1970 (regardless of what OS you're on), then you should use the method
I described, and you should either use or not use the leap seconds
depending on whether the other software does or doesn't.  If the other
software uses the Unix time function on Unix but some other system
service on other OS's, you should probably just do whatever the other
software does.  This one really isn't an Ada problem.  We could
conceivably propose a new addition to Ada.Calendar.Arithmetic:

function
Return_Current_Time_However_The_Other_Software_Maciej_Is_Using_Does_It;

but I sort of doubt that a proposal like that would be accepted.

                          -- Adam






^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-24 15:24             ` Adam Beneschan
@ 2007-07-25  7:26               ` Maciej Sobczak
  2007-07-25  7:42                 ` AW: " Grein, Christoph (Fa. ESG)
  0 siblings, 1 reply; 17+ messages in thread
From: Maciej Sobczak @ 2007-07-25  7:26 UTC (permalink / raw)


On 24 Lip, 17:24, Adam Beneschan <a...@irvine.com> wrote:

> > The problem is that I need just a number of seconds (this is for
> > interfacing with other software which uses that Unix-like time
> > descriptions), so I cannot use the value which is broken down into
> > several components.
>
> Why not?  Differences returns the result in "days" and "seconds", and
> you should be able to convert the "days" to seconds by multiplying it
> by a value that I just recently helped my 9-year-old figure out, and
> then adding the result to the second value, and then maybe adding the
> leap seconds (see below).

Right. I didn't notice that it's just two components, not more
(without years, months and days).

> We could
> conceivably propose a new addition to Ada.Calendar.Arithmetic:
>
> function
> Return_Current_Time_However_The_Other_Software_Maciej_Is_Using_Does_It;
>
> but I sort of doubt that a proposal like that would be accepted.

On my system Ada.Calendar.Time_Of and Ada.Calendar.Formatting.Time_Of
behave *differenty* with the same arguments, so with such a mess
already in the library no additional proposal could hurt...

Thank you for pointing me in the right direction, I was able now to
get the expected values by using Ada.Calendar.Formatting.Time_Of.

--
Maciej Sobczak
http://www.msobczak.com/




^ permalink raw reply	[flat|nested] 17+ messages in thread

* AW: Getting current date and time
  2007-07-25  7:26               ` Maciej Sobczak
@ 2007-07-25  7:42                 ` Grein, Christoph (Fa. ESG)
  0 siblings, 0 replies; 17+ messages in thread
From: Grein, Christoph (Fa. ESG) @ 2007-07-25  7:42 UTC (permalink / raw)
  To: comp.lang.ada

> On my system Ada.Calendar.Time_Of and Ada.Calendar.Formatting.Time_Of
> behave *differenty* with the same arguments, so with such a mess
> already in the library no additional proposal could hurt...

If you mean a difference of 23 s, this is the number of leap seconds
since 1972.

Check the constant Leap_Support in Ada.Calendar'Body in your compiler
version of GNAT, it should be False in order to ignore the leap seconds.


Eurocopter Deutschland GmbH
Sitz der Gesellschaft/Registered Office: Donauwoerth
Registergericht/Registration Court: Amtsgericht Augsburg HRB 16508
Vorsitzender des Aufsichtsrates/Chairman of the Supervisory Board: Dr. Lutz Bertling
Geschaeftsfuehrung/Board of Management:
Dr. Wolfgang Schoder, Vorsitzender/CEO; Friedrich-Wilhelm Hormel; Ralf Barnscheidt

CONFIDENTIALITY NOTICE 

This communication and the information it contains is intended for the addressee(s) named above and for no other persons or organizations. It is confidential and may be legally privileged and protected by law. The unauthorized use, copying or disclosure of this communication or any part of it is prohibited and may be unlawful. 
If you have received this communication in error, kindly notify us by return e-mail and discard and/or delete the communication. Thank you very much. 
It is possible for e-mails to be intercepted or affected by viruses. Whilst we maintain virus checks on our e-mails, we accept no liability for viruses or other material which might be introduced with this message. 




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-24  8:53           ` Maciej Sobczak
  2007-07-24  9:41             ` Georg Bauhaus
  2007-07-24 15:24             ` Adam Beneschan
@ 2007-07-28  8:20             ` Wilhelm Spickermann
  2 siblings, 0 replies; 17+ messages in thread
From: Wilhelm Spickermann @ 2007-07-28  8:20 UTC (permalink / raw)


Maciej Sobczak wrote:

>> In Ada 2005, this is handled by the Differences procedure in
>> Ada.Calendar.Arithmetic (9.6.1).  You can use
>> Ada.Calendar.Time_Of to create the Time value for January 1,
>> 1970, and then use that as a parameter to Differences.
> 
> The problem is that I need just a number of seconds (this is
> for interfacing with other software which uses that Unix-like
> time descriptions), so I cannot use the value which is broken
> down into several components.
> 

Then the situation contains even more problems. Every Unix time_t
value has two different meanings depending on the currently(!)
used configuration of the machine. If the local time
configuration (/etc/localtime) is taken from one of the "real"
TZ-Files, then a time_t value of 946684900 decribes the time
"1-jan-2000 00:01:18 UTC". But if the system is configured to
use "posix" TZ-Files, then the same timestamp describes
"1-jan-2000 00:01:40 UTC". 

So if you want to produce unix compatible time stamps, you will
have to know the configuration of the destination machine at the
time when the time_t value will be processed. 

If you want to interpret time stamps, you need to know the
configuration of the creating machine at the time this time
stamp was made. 

If the configuration is one of the "posix" ones, then it's
impossible to create time stamps representing times during
positive leap seconds. Conversely its possible to create time
stamps for times during negative leap seconds leaving us with
time stamps corresponding to no point in real time. Good thing,
that there were no negative leap seconds yet...

If the configuration is one of the "real" ones, then you cannot
compute date strings for time_t values in the far future (more
than about half a year), as the result depends on decisions not
made yet (leap second insertion).

Yet another problem: For historical data the TZ-Files cannot be
taken for real without checking. As TZ-Files fail to have any
representation for "we don't know" or "well, it depends on ...",
many known problems had to be ignored when creating the
TZ-Files. The comments in the source files of the ZIC (Zone
Information Compiler; ZIC produces TZ-Files) should be consulted
if necessary. 

Wilhelm Spickermann




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Getting current date and time
  2007-07-23 20:08       ` Maciej Sobczak
  2007-07-23 21:43         ` Adam Beneschan
@ 2007-08-01  9:45         ` Jacob Sparre Andersen
  1 sibling, 0 replies; 17+ messages in thread
From: Jacob Sparre Andersen @ 2007-08-01  9:45 UTC (permalink / raw)


Maciej Sobczak wrote:

> Still, I don't know how to portably get the number of seconds in the
> Unix epoch (for example, now is 1185221230). The built-in Duration
> type is not guaranteed to have the necessary range.  How to solve
> it?

It sounds like your program is intended to run on POSIX systems, so
why don't you use the appropriate POSIX functions?

declare
   use POSIX.Calendar;
   Wish : POSIX.Seconds;
begin
   Wish := POSIX.Get_Seconds (Time => To_Timespec (Date => Clock));
end;

Greetings,

Jacob
-- 
�If you're going to have crime,
 it might as well be organized crime.�      -- Lord Vetinari



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2007-08-01  9:45 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-22 21:21 Getting current date and time Maciej Sobczak
2007-07-22 23:00 ` Martin
2007-07-23 15:24   ` koburtch
2007-07-23 19:57   ` Maciej Sobczak
2007-07-23 20:02     ` Maciej Sobczak
2007-07-23 20:08       ` Maciej Sobczak
2007-07-23 21:43         ` Adam Beneschan
2007-07-24  8:53           ` Maciej Sobczak
2007-07-24  9:41             ` Georg Bauhaus
2007-07-24  9:58               ` Maciej Sobczak
2007-07-24 15:24             ` Adam Beneschan
2007-07-25  7:26               ` Maciej Sobczak
2007-07-25  7:42                 ` AW: " Grein, Christoph (Fa. ESG)
2007-07-28  8:20             ` Wilhelm Spickermann
2007-08-01  9:45         ` Jacob Sparre Andersen
2007-07-23 21:39       ` Adam Beneschan
2007-07-23 19:26 ` Gautier

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