comp.lang.ada
 help / color / mirror / Atom feed
* Calculating the "until" in delay until...?
@ 1997-08-12  0:00 Dale Stanbrough
  1997-08-12  0:00 ` Jon S Anthony
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Dale Stanbrough @ 1997-08-12  0:00 UTC (permalink / raw)



I wanted to write some code to delay until 8.00 am the next morning
(to email me if an Ada dist. server wasn't running). Unfortunately
it seems that to calculate a time until requires you to reinvent
the wheel!

Could someone tell me if there is a fault in this reasoning (or
a better way of doing this)?

If i want to "delay until", i have to provide a value of type
Calendar.Time. I can produce the time of "8.00 the next morning"
by finding out today's time, adding on a day, and using
Calendar.Time_Of. Yet adding on a day may require moving to the
next month. etc. etc. etc, so it seems i have to write a bit of
code to handle these date manipulations.


Dale




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

* Re: Calculating the "until" in delay until...?
  1997-08-12  0:00 Calculating the "until" in delay until...? Dale Stanbrough
  1997-08-12  0:00 ` Jon S Anthony
@ 1997-08-12  0:00 ` Gary Howell
  1997-08-12  0:00 ` John Woodruff
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Gary Howell @ 1997-08-12  0:00 UTC (permalink / raw)



In article <5spn9u$hk5$1@goanna.cs.rmit.edu.au>,
	Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU> writes:
>I wanted to write some code to delay until 8.00 am the next morning
>(to email me if an Ada dist. server wasn't running). Unfortunately
>it seems that to calculate a time until requires you to reinvent
>the wheel!
>
>Could someone tell me if there is a fault in this reasoning (or
>a better way of doing this)?

Here is a wheel that has already been invented ;-).

http://wuarchive.wustl.edu/languages/ada/userdocs/html/cardcat/date.html

Download and compile.  It will do just what you want.

Regards,

Gary
-- 
--|----------------------------------------------------------------------
--|Gary L. Howell                     | EMAIL  G.Howell@cerc.wes.army.mil
--|Coastal and Hydraulics Laboratory  | Voice  601-634-2006
--|USAE Waterways Experiment Station  | FAX    601-634-3151
--|----------------------------------------------------------------------





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

* Re: Calculating the "until" in delay until...?
  1997-08-12  0:00 Calculating the "until" in delay until...? Dale Stanbrough
  1997-08-12  0:00 ` Jon S Anthony
  1997-08-12  0:00 ` Gary Howell
@ 1997-08-12  0:00 ` John Woodruff
  1997-08-13  0:00   ` Dale Stanbrough
  1997-08-13  0:00 ` David C. Hoos, Sr.
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 10+ messages in thread
From: John Woodruff @ 1997-08-12  0:00 UTC (permalink / raw)



>>>>> "Dale" == Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU> writes:
In article <5spn9u$hk5$1@goanna.cs.rmit.edu.au> Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU> writes:


    > I wanted to write some code to delay until 8.00 am the next
    > morning (to email me if an Ada dist. server wasn't
    > running). Unfortunately it seems that to calculate a time until
    > requires you to reinvent the wheel!

Well you're right, there is a fair amount of work involved.  But there's
no reason to actually *do* it.  

Instead, go over to the PAL library and acquire the estimable
TOD_Utilities by Geoff Mendal. 

Brief excerpt from the header follows.  (This might not be the most
up-to-date version, and I'm by no means confident that the author's
affiliation is still accurate).


-------- SIMTEL20 Ada Software Repository Prologue ------------
--                                                           -*
-- Unit name    : package Tod_Utilities
-- Version      : 2.0 (THEB048)
-- Author       : Geoffrey O. Mendal
--              : Computer Systems Laboratory, ERL 456
--              : Stanford University
--              : Stanford, CA  94305
--              : (415) 723-1414 or 723-1175
-- DDN Address  : Mendal@Sierra.Stanford.Edu
-- Copyright    : (c) 1985, 1988 Geoffrey O. Mendal
-- Date created : Mon 11 Nov 85
-- Release date : Sun 25 Dec 85
-- Last update  : MENDAL Thu 04 Feb 88
-- Machine/System Compiled/Run on : DG MV10000, ROLM ADE
--                                  VAX 11/780, DEC ACS
--                                  RATIONAL R1000
--                                  SUN/3 UNIX, VERDIX VADS
--                                  SEQUENT DYNIX, VERDIX VADS
-- Dependent Units : package CALENDAR
--                   generic package Search_Utilities  <<also in PAL>>
--                                                           -*
-- This package will provide direct conversion from an external
-- time/date string to the internal Ada CALENDAR.TIME representation
-- and vice versa.  Most free format external representations are
-- supported.  Components of an external format include:
--   Year, Month and Day (as numbers and strings), Hour, Minutes,
--   and Seconds
-- As long as the external representation can be parsed unambiguously,
-- this package should be able to handle the conversion.  Examples of
-- legal external formats:
--   7pm Fr March 12, 1982
--   15 Dec. 84 12:36PM
--   YESTERDAY 3PM
--   6/01/83          <-- defaults to 12:00:00AM
--   3:45AM           <-- defaults to the current date
--   18:07:35         <-- defaults to the current date
--   8-26             <-- defaults to 12:00:00AM of the current year
--   friday           <-- defaults to 12:00:00AM of the current or next




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

* Re: Calculating the "until" in delay until...?
  1997-08-12  0:00 Calculating the "until" in delay until...? Dale Stanbrough
@ 1997-08-12  0:00 ` Jon S Anthony
  1997-08-12  0:00 ` Gary Howell
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Jon S Anthony @ 1997-08-12  0:00 UTC (permalink / raw)



In article <5spn9u$hk5$1@goanna.cs.rmit.edu.au> Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU> writes:

> If i want to "delay until", i have to provide a value of type
> Calendar.Time. I can produce the time of "8.00 the next morning"
> by finding out today's time, adding on a day, and using
> Calendar.Time_Of. Yet adding on a day may require moving to the
> next month. etc. etc. etc, so it seems i have to write a bit of
> code to handle these date manipulations.

I think you may be right about this.  My reading of 9.6 is that
whether you will need to do this is implementation dependent.  If you
like rumor (:-), I seem to recall that GNAT does work this way on some
platforms.

/Jon
-- 
Jon Anthony
OMI, Belmont, MA 02178, 617.484.3383 
"Nightmares - Ha!  The way my life's been going lately,
 Who'd notice?"  -- Londo Mollari




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

* Re: Calculating the "until" in delay until...?
  1997-08-12  0:00 Calculating the "until" in delay until...? Dale Stanbrough
                   ` (5 preceding siblings ...)
       [not found] ` <01bca7cd$f39f5110$4d8371a5@dhoossr>
@ 1997-08-13  0:00 ` David C. Hoos, Sr.
  6 siblings, 0 replies; 10+ messages in thread
From: David C. Hoos, Sr. @ 1997-08-13  0:00 UTC (permalink / raw)



How about
   delay until Ada.Calendar.Time of
      (Year => 1997,
        Month => 8,
        Day => 12,
        Seconds => Duration (8.0 * 60.0 * 60.0));
Or, if you wish to compute when "*:00 a.m. tomorrow" is you could
declare
  Year : Ada.Calendar.Year_number;
  Month : Ada.Calendar.MonthNumber;
  Day : Ada.Calendar.Day_Number;
  Seconds : Ada.Calendar.Day_Duration;
begin
  Ada.Calendar.Split
    (Date => Ada.Calendar.Clock,
      Year => Year,
      Month => Month,
      Day => Day,
      Seconds => Seconds);
   delay until Ada.Calendar.Time_Of
      (Year => Year,
        Month => Month,
        Day => Day,
        Seconds => Duration (8.0 * 60.0 * 60.0)) +
          Duration (24.0 * 60.0 *60.0);
  end;

David C. Hoos, Sr.

Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU> wrote in article
<5spn9u$hk5$1@goanna.cs.rmit.edu.au>...
> I wanted to write some code to delay until 8.00 am the next morning
> (to email me if an Ada dist. server wasn't running). Unfortunately
> it seems that to calculate a time until requires you to reinvent
> the wheel!
> 
> Could someone tell me if there is a fault in this reasoning (or
> a better way of doing this)?
> 
> If i want to "delay until", i have to provide a value of type
> Calendar.Time. I can produce the time of "8.00 the next morning"
> by finding out today's time, adding on a day, and using
> Calendar.Time_Of. Yet adding on a day may require moving to the
> next month. etc. etc. etc, so it seems i have to write a bit of
> code to handle these date manipulations.
> 
> 
> Dale
> 




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

* Re: Calculating the "until" in delay until...?
       [not found] ` <01bca7cd$f39f5110$4d8371a5@dhoossr>
@ 1997-08-13  0:00   ` Samuel Mize
  1997-08-13  0:00     ` Robert A Duff
  0 siblings, 1 reply; 10+ messages in thread
From: Samuel Mize @ 1997-08-13  0:00 UTC (permalink / raw)



David C. Hoos, Sr. wrote:
> Or, if you wish to compute when "8:00 a.m. tomorrow" is you could
...
>    delay until Ada.Calendar.Time_Of
>       (Year => Year,
>         Month => Month,
>         Day => Day,
>         Seconds => Duration (8.0 * 60.0 * 60.0)) +
>           Duration (24.0 * 60.0 *60.0);
>   end;

Sorry, the parameter Seconds is of type Day_Duration, not
Duration, and must be less than 86400 (which is 24*60*60).
Instant constraint error.

Sam Mize




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

* Re: Calculating the "until" in delay until...?
  1997-08-12  0:00 Calculating the "until" in delay until...? Dale Stanbrough
                   ` (2 preceding siblings ...)
  1997-08-12  0:00 ` John Woodruff
@ 1997-08-13  0:00 ` David C. Hoos, Sr.
  1997-08-13  0:00 ` Samuel Tardieu
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: David C. Hoos, Sr. @ 1997-08-13  0:00 UTC (permalink / raw)



How about
   delay until ada.Calendar.Time of
      (Year => 1997,
        Month => 8,
        Day => 12,
        seconds => 8.0 * 60.0 * 60.0);

David C. Hoos, Sr.

Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU> wrote in article
<5spn9u$hk5$1@goanna.cs.rmit.edu.au>...
> I wanted to write some code to delay until 8.00 am the next morning
> (to email me if an Ada dist. server wasn't running). Unfortunately
> it seems that to calculate a time until requires you to reinvent
> the wheel!
> 
> Could someone tell me if there is a fault in this reasoning (or
> a better way of doing this)?
> 
> If i want to "delay until", i have to provide a value of type
> Calendar.Time. I can produce the time of "8.00 the next morning"
> by finding out today's time, adding on a day, and using
> Calendar.Time_Of. Yet adding on a day may require moving to the
> next month. etc. etc. etc, so it seems i have to write a bit of
> code to handle these date manipulations.
> 
> 
> Dale
> 




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

* Re: Calculating the "until" in delay until...?
  1997-08-12  0:00 Calculating the "until" in delay until...? Dale Stanbrough
                   ` (3 preceding siblings ...)
  1997-08-13  0:00 ` David C. Hoos, Sr.
@ 1997-08-13  0:00 ` Samuel Tardieu
       [not found] ` <01bca7cd$f39f5110$4d8371a5@dhoossr>
  1997-08-13  0:00 ` David C. Hoos, Sr.
  6 siblings, 0 replies; 10+ messages in thread
From: Samuel Tardieu @ 1997-08-13  0:00 UTC (permalink / raw)
  To: Dale Stanbrough


>>>>> "Dale" == Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU> writes:

Dale> If i want to "delay until", i have to provide a value of type
Dale> Calendar.Time. I can produce the time of "8.00 the next morning"
Dale> by finding out today's time, adding on a day, and using
Dale> Calendar.Time_Of. Yet adding on a day may require moving to the
Dale> next month. etc. etc. etc, so it seems i have to write a bit of
Dale> code to handle these date manipulations.

Mmm... I cannot understand your reasoning. Why don't you use a piece
of code like: (untested)

with Ada.Calendar; use Ada.Calendar;

function Next_Morning_Eight_AM return Time is

   NMEA_Year    : Year_Number;
   NMEA_Month   : Month_Number;
   NMEA_Day     : Day_Number;
   NMEA_Seconds : Day_Duration;

begin

   --  Split (now + 24 hours) into Year, Month, Day and Seconds
   Split (Clock + Day_Duration'Last,
          NMEA_Year, NMEA_Month, NMEA_Day, NMEA_Seconds);

   --  Combine this back (with Seconds := 8 hours since midnight) into 
   --  Time
   return Time_Of (NMEA_Year, NMEA_Month, NMEA_Day, 8.0 * 3600);

end Next_Morning_Eight_AM;

then do a

  delay until Next_Morning_Eight_AM;

?

  Sam
-- 
Samuel Tardieu -- sam@ada.eu.org




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

* Re: Calculating the "until" in delay until...?
  1997-08-12  0:00 ` John Woodruff
@ 1997-08-13  0:00   ` Dale Stanbrough
  0 siblings, 0 replies; 10+ messages in thread
From: Dale Stanbrough @ 1997-08-13  0:00 UTC (permalink / raw)



 -- As long as the external representation can be parsed unambiguously,
 -- this package should be able to handle the conversion.  Examples of
 -- legal external formats:
 --   7pm Fr March 12, 1982
 --   15 Dec. 84 12:36PM
 --   YESTERDAY 3PM
 --   6/01/83          <-- defaults to 12:00:00AM

I wonder how 6/01/83 could be considered unambiguous!

Thanks for all the info anyway.


Dale




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

* Re: Calculating the "until" in delay until...?
  1997-08-13  0:00   ` Samuel Mize
@ 1997-08-13  0:00     ` Robert A Duff
  0 siblings, 0 replies; 10+ messages in thread
From: Robert A Duff @ 1997-08-13  0:00 UTC (permalink / raw)



In article <33F1FC6A.2EE6@link.com>, Samuel Mize  <smize@link.com> wrote:
>Sorry, the parameter Seconds is of type Day_Duration, not
>Duration, and must be less than 86400 (which is 24*60*60).
>Instant constraint error.

Was the goal to produce a Time value equal to "8:00 am tomorrow"?
(I wasn't paying too much attention to the original post.)
How about:

    Now: constant Time := Clock;
    This_Morning: constant Time
       := Time_Of(Year(Now), Month(Now), Day(Now),
                  Seconds => 8.0*60.0*60.0);
    Tomorrow_Morning: constant Time := This_Morning + 24.0*60.0*60.0;
    ...
    delay until Tomorrow_Morning;

?

- Bob




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

end of thread, other threads:[~1997-08-13  0:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-08-12  0:00 Calculating the "until" in delay until...? Dale Stanbrough
1997-08-12  0:00 ` Jon S Anthony
1997-08-12  0:00 ` Gary Howell
1997-08-12  0:00 ` John Woodruff
1997-08-13  0:00   ` Dale Stanbrough
1997-08-13  0:00 ` David C. Hoos, Sr.
1997-08-13  0:00 ` Samuel Tardieu
     [not found] ` <01bca7cd$f39f5110$4d8371a5@dhoossr>
1997-08-13  0:00   ` Samuel Mize
1997-08-13  0:00     ` Robert A Duff
1997-08-13  0:00 ` David C. Hoos, Sr.

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