home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / database / 8791 < prev    next >
Encoding:
Text File  |  1993-01-04  |  3.4 KB  |  123 lines

  1. Newsgroups: comp.databases
  2. Path: sparky!uunet!gatech!usenet.ins.cwru.edu!agate!dog.ee.lbl.gov!news!humu!pegasus!tleylan
  3. From: tleylan@pegasus.com (Tom Leylan)
  4. Subject: Re: Pls help: algorithm wanted (xbase, pref foxpro)
  5. Message-ID: <1993Jan3.103406.28479@pegasus.com>
  6. Organization: Pegasus,  Honolulu
  7. References: <durai.102.725742702@ortta.umn.edu>
  8. Date: Sun, 3 Jan 93 10:34:06 GMT
  9. Lines: 112
  10.  
  11. durai@ortta.umn.edu (Durai Venkatasubramanian) writes:
  12.  
  13. >I need an algorithm to accomplish a date comparison task.  Any help will be 
  14. >appreciated and gratefully remembered for life.
  15.  
  16. The following will do what you want.  I started with the other poster's
  17. code and "structured" it (a little better (in my opinion)) and as you
  18. will notice the code resides in a function which is called repeatedly
  19. until the function sends back a signal saying it is done.
  20.  
  21. It is in Clipper 5.0 but I don't think there is anything that won't
  22. translate into FoxPro.  I left some of the Clipper-only initializations
  23. and stuff out to facilitate it.
  24.  
  25. I wrote another version which adds a little more complexity but also
  26. adds flexibility in that the PrintRate() function didn't actually print
  27. the results but rather returned them to Main() which could then print
  28. the BegDate, EndDate and Status or do whatever else it might want to
  29. like write it to a file, send it through a fax card or whatever.
  30.  
  31. Oh... you should add append one extra record to your database which is
  32. a dummy that covers all dates from the last "real" one to the end of
  33. time or 01/01/95 - 12/31/99 in your sample and figuring that the end
  34. of time is the end of this century.  By adding the record some code is
  35. eliminated which has to check if the EOF() condition was a false hit
  36. on the last record.  Personally I'd make the status "unknown" rather
  37. than "uncovered" on that dummy record because it indicates you shot
  38. past the scope of the system.  The person would be uncovered but it
  39. might serve as a warning that you typed a date in wrong or something.
  40.  
  41. No big deal and you know what you're doing better than I do.
  42.  
  43. Oh... the first line is just a Clipper header file which I reference
  44. in PrintRate() to SET SOFTSEEK on and off again without having to know
  45. what the status is in the rest of the application.
  46.  
  47. tom
  48.  
  49.  
  50. #include "set.ch"
  51.  
  52. FIELD START_DATE, END_DATE, STATUS
  53.  
  54. MEMVAR getlist
  55.  
  56. FUNCTION Main
  57.    LOCAL dBeg, dEnd
  58.    LOCAL aDates[ 2 ]
  59.  
  60.    USE RATE EXCLUSIVE NEW ALIAS Rate
  61.    INDEX ON Rate->START_DATE TO START
  62.  
  63.    CLS
  64.  
  65.    aDates[ 1 ] := CTOD( "" )
  66.    aDates[ 2 ] := CTOD( "" )
  67.  
  68.    @ 0, 0 SAY "Beg Date : " GET aDates[ 1 ] PICT "@D"
  69.    @ 2, 0 SAY "End Date : " GET aDates[ 2 ] PICT "@D"
  70.    READ
  71.  
  72.    ?
  73.    ? "Subcontract Period: " +;
  74.       DTOC( aDates[ 1 ] ) + " - " + DTOC( aDates[ 2 ] )
  75.    ?
  76.  
  77.    WHILE PrintRate( aDates )
  78.    ENDDO
  79.  
  80.    CLOSE Rate
  81.  
  82.    RETURN NIL
  83.  
  84.  
  85. FUNCTION PrintRate( aDates )
  86.    LOCAL lRet := .F.
  87.  
  88.    LOCAL xSoft := SET( _SET_SOFTSEEK, .T. )
  89.  
  90.    SEEK aDates[ 1 ]
  91.  
  92.    IF ( Rate->( EOF() ) )
  93.       OutStat( aDates[ 1 ], aDates[ 2 ], "Uncovered" )
  94.  
  95.    ELSE
  96.  
  97.       IF ! ( aDates[ 1 ] == Rate->START_DATE )
  98.          SKIP -1
  99.       ENDIF
  100.  
  101.       IF ( aDates[ 2 ] <= Rate->END_DATE )
  102.          OutStat( aDates[ 1 ], aDates[ 2 ], Rate->STATUS )
  103.  
  104.       ELSE
  105.          OutStat( aDates[ 1 ], Rate->END_DATE, Rate->STATUS )
  106.          aDates[ 1 ] := ( Rate->END_DATE + 1 )
  107.          lRet := .T.
  108.  
  109.       ENDIF
  110.  
  111.    ENDIF
  112.  
  113.    SET( _SET_SOFTSEEK, xSoft )
  114.  
  115.    RETURN lRet
  116.  
  117.  
  118. FUNCTION OutStat( dBeg, dEnd, cMsg )
  119.    ? DTOC( dBeg ) + " - " + DTOC( dEnd ) + " = " + cMsg
  120.  
  121.    RETURN NIL
  122.  
  123.