home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / INTERNET / UPC2S1.ZIP / DATER.C < prev    next >
C/C++ Source or Header  |  1992-11-27  |  2KB  |  58 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    d a t e r . c                                                   */
  3. /*                                                                    */
  4. /*    Date formatting routines for UUPC/extended                      */
  5. /*                                                                    */
  6. /*    Copyright (c) 1991, Andrew H. Derbyshire                        */
  7. /*--------------------------------------------------------------------*/
  8.  
  9. /*--------------------------------------------------------------------*/
  10. /*                        System include files                        */
  11. /*--------------------------------------------------------------------*/
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <time.h>
  16.  
  17. /*--------------------------------------------------------------------*/
  18. /*                    UUPC/extended include files                     */
  19. /*--------------------------------------------------------------------*/
  20.  
  21. #include "lib.h"
  22. #include "dater.h"
  23.  
  24. /*--------------------------------------------------------------------*/
  25. /*    d a t e r                                                       */
  26. /*                                                                    */
  27. /*    Format the date and time as mm/dd-hh:mm                         */
  28. /*--------------------------------------------------------------------*/
  29.  
  30. char *dater( const time_t t , char *buf)
  31. {                              /* ....+....1. + 1 to terminate */
  32.    static char format[DATEBUF] = "%m/%d-%H:%M";
  33.    static char mybuf[DATEBUF]  = "           ";
  34.    static char sabuf[DATEBUF]  = "           ";
  35.    static char never[DATEBUF]  = "  (never)  ";
  36.    static char missing[DATEBUF]= " (missing) ";
  37.    static time_t last = -1;
  38.  
  39.    if ( buf == NULL )
  40.       buf = mybuf;
  41.  
  42.    if ( t == 0 )
  43.       strcpy( buf, never);
  44.    else if ( t == -1 )
  45.       strcpy( buf, missing );
  46.    else {
  47.       time_t now = t / 60;
  48.       if ( last != now )
  49.       {
  50.          strftime( sabuf, sizeof( format ) , format ,  localtime( &t ));
  51.          last = now;
  52.       }
  53.       strcpy( buf, sabuf );
  54.    } /* else */
  55.  
  56.    return buf;
  57. } /* dater */
  58.