home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 1 / FishNMoreVol1.bin / more / code_examples / librar / julediff.c < prev    next >
Text File  |  1989-02-08  |  1KB  |  53 lines

  1. /*--------------------------------------*/
  2. /*                    */
  3. /*             JULEDIFF(X,X)        */
  4. /*                    */
  5. /* Returns the julian difference of two */
  6. /* dates passed in the arguments. The   */
  7. /* number returned will never be nega-  */
  8. /* tive.                */
  9. /*                    */
  10. /*       Written by John Callicotte    */
  11. /*                    */
  12. /*--------------------------------------*/
  13. # include "string.h"
  14. julediff(a,b)
  15. char a[8],b[8];
  16. {
  17.         int j,x,year[2],jules[2];
  18.         char date[2][8];
  19.         x=strncmp(a,b,8);
  20.         if (!x)
  21.             return(0);
  22.         if (x>0){
  23.             for (j=0;j<8;j++){
  24.                  date[0][j]=b[j];
  25.                  date[1][j]=a[j];
  26.             }
  27.         }
  28.         else{
  29.             for (j=0;j<8;j++){
  30.                   date[0][j]=a[j];
  31.                   date[1][j]=b[j];
  32.             }
  33.         }
  34.         for (j=0;j<2;j++){
  35.              year[j]=(date[j][6]-48)*10+date[j][7]-48;
  36.              jules[j]=getjule(date[j]);
  37.         }
  38.         if (year[0]==year[1])
  39.             return(jules[1]-jules[0]);
  40.         x=365-jules[0];
  41.         if (!efactor(year[0],4))
  42.             x++;
  43.         if (year[0]==year[1]-1)
  44.             return(x+jules[1]);
  45.         for (j=year[0]+1;j<year[1];j++){
  46.              x+=365;
  47.              if (!efactor(j,4))
  48.                  x++;
  49.         }
  50.         x+=jules[1];
  51.         return(x);
  52. }
  53.