home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES1.ZIP / LIB / dater.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-11  |  3.0 KB  |  81 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    d a t e r . c                                                   */
  3. /*                                                                    */
  4. /*    Date formatting routines for UUPC/extended                      */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  9. /*       Wonderworks.                                                 */
  10. /*                                                                    */
  11. /*       All rights reserved except those explicitly granted by       */
  12. /*       the UUPC/extended license agreement.                         */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: dater.c 1.2 1993/10/09 15:46:15 rhg Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: dater.c $
  24.  *     Revision 1.2  1993/10/09  15:46:15  rhg
  25.  *     ANSIify the source
  26.  *
  27.  *     Revision 1.2  1993/10/09  15:46:15  rhg
  28.  *     ANSIify the source
  29.  *
  30.  */
  31.  
  32. /*--------------------------------------------------------------------*/
  33. /*                        System include files                        */
  34. /*--------------------------------------------------------------------*/
  35.  
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <time.h>
  39.  
  40. /*--------------------------------------------------------------------*/
  41. /*                    UUPC/extended include files                     */
  42. /*--------------------------------------------------------------------*/
  43.  
  44. #include "lib.h"
  45. #include "dater.h"
  46.  
  47. /*--------------------------------------------------------------------*/
  48. /*    d a t e r                                                       */
  49. /*                                                                    */
  50. /*    Format the date and time as mm/dd-hh:mm                         */
  51. /*--------------------------------------------------------------------*/
  52.  
  53. char *dater( const time_t t , char *buf)
  54. {                              /* ....+....1. + 1 to terminate */
  55.    static char format[DATEBUF] = "%m/%d-%H:%M";
  56.    static char mybuf[DATEBUF]  = "           ";
  57.    static char sabuf[DATEBUF]  = "           ";
  58.    static char never[DATEBUF]  = "  (never)  ";
  59.    static char missing[DATEBUF]= " (missing) ";
  60.    static time_t last = (time_t) -1L;
  61.  
  62.    if ( buf == NULL )
  63.       buf = mybuf;
  64.  
  65.    if ( t == 0 )
  66.       strcpy( buf, never);
  67.    else if ( t == -1 )
  68.       strcpy( buf, missing );
  69.    else {
  70.       time_t now = t / 60;
  71.       if ( last != now )
  72.       {
  73.          strftime( sabuf, sizeof( format ) , format ,  localtime( &t ));
  74.          last = now;
  75.       }
  76.       strcpy( buf, sabuf );
  77.    } /* else */
  78.  
  79.    return buf;
  80. } /* dater */
  81.