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

  1. /*--------------------------------------------------------------------*/
  2. /*    a r p a d a t e                                                 */
  3. /*                                                                    */
  4. /*    Return the current date/time in RFC 822 format                  */
  5. /*                                                                    */
  6. /*    ctime() format 'Mon Nov 21 11:31:54 1983\n\0'                   */
  7. /*                                                                    */
  8. /*    RFC822 format  'Mon, 21 Nov 1983 11:31:54 PST\0' or             */
  9. /*    RFC822 format  'Mon, 16 May 1988 02:13:10 -0700\0'              */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. /*--------------------------------------------------------------------*/
  13. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  14. /*       Wonderworks.                                                 */
  15. /*                                                                    */
  16. /*       All rights reserved except those explicitly granted by       */
  17. /*       the UUPC/extended license agreement.                         */
  18. /*--------------------------------------------------------------------*/
  19.  
  20. /*--------------------------------------------------------------------*/
  21. /*                          RCS Information                           */
  22. /*--------------------------------------------------------------------*/
  23.  
  24. /*
  25.  *    $Id: arpadate.c 1.6 1993/11/15 05:43:29 ahd Exp $
  26.  *
  27.  *    Revision history:
  28.  *    $Log: arpadate.c $
  29.  *     Revision 1.6  1993/11/15  05:43:29  ahd
  30.  *     Twiddle, twiddle ...
  31.  *
  32.  *     Revision 1.5  1993/11/13  17:37:02  ahd
  33.  *     More date twiddling
  34.  *
  35.  *     Revision 1.4  1993/11/06  16:56:13  ahd
  36.  *     Use localtime to determine tz offset
  37.  *
  38.  *     Revision 1.3  1993/10/28  00:18:10  ahd
  39.  *     Apply Kai Uwe Rommel's fix to use TZ offset in hours rather than
  40.  *     time zone
  41.  *
  42.  */
  43.  
  44. #include <stdio.h>
  45. #include <time.h>
  46. #include <string.h>
  47.  
  48. #include "lib.h"
  49. #include "arpadate.h"
  50.  
  51. /*--------------------------------------------------------------------*/
  52. /*              Macro to return sign of a signed number               */
  53. /*--------------------------------------------------------------------*/
  54.  
  55. #define sign(x) ((x < 0) ? -1 : 1 )
  56.  
  57. /*--------------------------------------------------------------------*/
  58. /*       a r p a d a t e                                              */
  59. /*                                                                    */
  60. /*       Format current time into RFC-822 date                        */
  61. /*--------------------------------------------------------------------*/
  62.  
  63. char *arpadate( void )
  64. {
  65.    static char format[] = "%a, %d %b %Y %H:%M:%S";
  66.    static char adate[64], zone[32];
  67.    time_t t;
  68.    struct tm lt, gm;
  69.  
  70.    time( &t );
  71.    lt = *localtime(&t);
  72.  
  73. /*--------------------------------------------------------------------*/
  74. /*       Make time zone name, if necessary                            */
  75. /*--------------------------------------------------------------------*/
  76.  
  77.    if (zone[0] == 0) {            /* adjust for daylight savings time */
  78.       int offset;
  79.  
  80.       gm = *gmtime(&t);
  81.       offset = - (gm.tm_hour - lt.tm_hour) * 100;
  82.                                  /* This doesn't handle minutes, but
  83.                                     guess what ... the BC library
  84.                                     doesn't either.  AST doesn't
  85.                                     work, so what?                   */
  86.  
  87.       sprintf(zone, " %+05d", offset );
  88.    }
  89.  
  90. /*--------------------------------------------------------------------*/
  91. /*                 Format the new time and return it                  */
  92. /*--------------------------------------------------------------------*/
  93.  
  94.    strftime(adate, sizeof(adate), format, <);
  95.    strcat(adate, zone);
  96.  
  97.    return adate;
  98.  
  99. } /*arpadate*/
  100.