/* * Routine to convert a localtime(3) format date back into * a system format date. * * Hats off to Bob Kridle for the insight that the way to do * this is by binary search of the system date space. */ #include struct tm *localtime(); long emitl(dp) struct tm *dp; { long conv; register int i, bit; struct tm dcopy; dcopy = *dp; dp = &dcopy; conv = 0; for (i = 31; i >= 0; i--) { bit = 1 << i; conv |= bit; if (dcmp(localtime(&conv), dp) > 0) conv &= ~bit; } return(conv); } /* * Compare two localtime dates, return result. */ #define DECIDE(a) \ if (dp->a > dp2->a) \ return(1); \ if (dp->a < dp2->a) \ return(-1) static dcmp(dp, dp2) register struct tm *dp, *dp2; { DECIDE(tm_year); DECIDE(tm_mon); DECIDE(tm_mday); DECIDE(tm_hour); DECIDE(tm_min); DECIDE(tm_sec); return(0); }