From: durai@ortta.umn.edu (Durai Venkatasubramanian)
Subject: Re: Pls help: algorithm wanted (xbase, pref foxpro)
Organization: U of Mn
Date: Wed, 30 Dec 1992 23:09:45 GMT

In article <1992Dec30.214031.25907@almserv.uucp> g9utxu@fnma.COM (Tanin Uthayanaka) writes:
>From: g9utxu@fnma.COM (Tanin Uthayanaka)
>Subject: Re: Pls help: algorithm wanted (xbase, pref foxpro)
>Date: Wed, 30 Dec 1992 21:40:31 GMT

>I will attempt to help.
>
>First, I'm assuming that you have a rate database (lets call it RATE.DBF) with the 
>folowing field:
>
>	1 RATE
>	2 START_DATE
>	3 END_DATE
>	4 STATUS
>
>Second, the user enters dStart and dEnd
>
>Third, the program would do the following:
>
>@ 10,10 SAY "Subcontract Period: "+DTOC(dStart)+" - "+DTOC(dEnd)
>@ 11,0  SAY ""
>USE RATE
>INDEX ON START_DATE TO START
>SET SOFTSEEK ON
>SEEK dStart
>IF ! EOF()
>   IF dStart < RATE->START_DATE
>      @ ROW()+1,15 SAY DTOC(dStart)+"CLEAR ALL
>      @ ROW(),  30 SAY "Uncovered"
>   ENDIF
>   DO WHILE RATE->START_DATE >= dStart
>      IF RATE->END_DATE <= dEnd
>         @ ROW()+1,15 SAY DTOC(RATE->START_DATE)+" - "+DTOC(RATE->END_DATE)
>         @ ROW(),  30 SAY RATE->STATUS
>      ELSE
>         @ ROW()+1,15 SAY DTOC(RATE->END_DATE+1)+" - "+DTOC(dEnd)
>         @ ROW(),  30 SAY "Uncovered"
>         EXIT
>      ENDIF
>      SKIP +1
>      IF EOF()
>         SKIP -1
>         @ ROW()+1,15 SAY DTOC(RATE->END_DATE+1)+" - "+DTOC(dEnd)
>         @ ROW(),  30 SAY "Uncovered"
>         EXIT
>      ENDIF
>   ENDDO
>ELSE
>   @ ROW()+1,15 SAY DTOC(dStart)+" - "+DTOC(dEnd)
>   @ ROW(),  30 SAY "Uncovered"
>ENDIF
>SET SOFTSEEK OFF
>SET INDEX TO
>USE
>
>Hope this helps, I know it's hard coded but the algorithm is there.
>
>TU
>
>P.S. Hope there's no bug I took only 10 minutes to write the code and didn't have 
>     time to run the program


Thanks for responding.  

The program did not work.  I tried with the following data.

Rate.dbf                    program variables

stdate    enddate           sdate: 01/01/92
07/01/91  06/30/92          edate: 12/31/93
07/01/92  06/30/93

The program rejected the entire period as "uncovered", whereas the results 
should have been:

01/01/92 - 06/30/93  :covered
07/01/93 - 12/31/93  :uncovered

The program statements,
   IF dStart < RATE->START_DATE
      @ ROW()+1,15 SAY DTOC(dStart)+" - "+DTOC(RATE->START_DATE-1)
      @ ROW(),  30 SAY "Uncovered"
   ENDIF
   DO WHILE RATE->START_DATE >= dStart
if i am not wrong, do the same thing, or do different things for the same 
condition.  You are prompting an action if dstart<rate.startdate, and again 
if rate.startdate > dstart.  However, the problem does not lie here.

My problem is to compare part of date range for each record.  It is possible 
to pull all the records that cover the entire contract period.  Once that is 
done, how do we map part of the contract period, the starting period of 
which can be older than agreement start date and the ending period later 
than the agreement end date.  For example, if the contract period is 
01/01/92 to 12/31/94, how do i check for, say, 01/01/93 - 12/31/93 ?

Somehow, the situation seems to be very basic to me (i am tempted to defend 
my ignorance here, but the fact exists), and many of us would have dealt 
with similar requirements.  I was wondering if anybody had a readymade 
solution to this.

Thanks, anyway, for your time and effort.

Newsgroups: comp.databases