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

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