home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / SQDEV200.ZIP / SRC / CVTDATE.C < prev    next >
C/C++ Source or Header  |  1994-05-23  |  4KB  |  100 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *  Squish Developers Kit Source, Version 2.00                             *
  4.  *  Copyright 1989-1994 by SCI Communications.  All rights reserved.       *
  5.  *                                                                         *
  6.  *  USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE       *
  7.  *  SQUISH DEVELOPERS KIT LICENSING AGREEMENT IN SQDEV.PRN.  IF YOU DO NOT *
  8.  *  FIND THE TEXT OF THIS AGREEMENT IN THE AFOREMENTIONED FILE, OR IF YOU  *
  9.  *  DO NOT HAVE THIS FILE, YOU SHOULD IMMEDIATELY CONTACT THE AUTHOR AT    *
  10.  *  ONE OF THE ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO  *
  11.  *  USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE SQUISH          *
  12.  *  DEVELOPERS KIT LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE *
  13.  *  ABLE TO REACH WITH THE AUTHOR.                                         *
  14.  *                                                                         *
  15.  *  You can contact the author at one of the address listed below:         *
  16.  *                                                                         *
  17.  *  Scott Dudley       FidoNet     1:249/106                               *
  18.  *  777 Downing St.    Internet    sjd@f106.n249.z1.fidonet.org            *
  19.  *  Kingston, Ont.     CompuServe  >INTERNET:sjd@f106.n249.z1.fidonet.org  *
  20.  *  Canada  K7M 5N3    BBS         1-613-634-3058, V.32bis                 *
  21.  *                                                                         *
  22.  ***************************************************************************/
  23.  
  24. #include <time.h>
  25. #include "prog.h"
  26.  
  27. static int is_dst=-1;
  28.  
  29.  
  30. /* Find out the current status of daylight savings time */
  31.  
  32. static void near InitCvt(void)
  33. {
  34.   time_t tnow;
  35.  
  36.   tnow=time(NULL);
  37.  
  38.   is_dst=!! (localtime(&tnow)->tm_isdst);
  39. }
  40.  
  41.  
  42. /* Convert a DOS-style bitmapped date into a 'struct tm'-type date. */
  43.  
  44. struct tm * _fast DosDate_to_TmDate(union stamp_combo *dosdate,
  45.                                      struct tm *tmdate)
  46. {
  47.   if (is_dst==-1)
  48.     InitCvt();
  49.  
  50.   tmdate->tm_mday=dosdate->msg_st.date.da;
  51.   tmdate->tm_mon =dosdate->msg_st.date.mo-1;
  52.   tmdate->tm_year=dosdate->msg_st.date.yr+80;
  53.  
  54.   tmdate->tm_hour=dosdate->msg_st.time.hh;
  55.   tmdate->tm_min =dosdate->msg_st.time.mm;
  56.   tmdate->tm_sec =dosdate->msg_st.time.ss << 1;
  57.  
  58.   tmdate->tm_isdst=is_dst;
  59.  
  60.   return tmdate;
  61. }
  62.  
  63. /* Convert a 'struct tm'-type date into an Opus/DOS bitmapped date */
  64.  
  65. union stamp_combo * _fast TmDate_to_DosDate(struct tm *tmdate,
  66.                                              union stamp_combo *dosdate)
  67. {
  68.   dosdate->msg_st.date.da=tmdate->tm_mday;
  69.   dosdate->msg_st.date.mo=tmdate->tm_mon+1;
  70.   dosdate->msg_st.date.yr=(tmdate->tm_year < 80) ? 0 : tmdate->tm_year-80;
  71.  
  72.   dosdate->msg_st.time.hh=tmdate->tm_hour;
  73.   dosdate->msg_st.time.mm=tmdate->tm_min;
  74.   dosdate->msg_st.time.ss=tmdate->tm_sec >> 1;
  75.  
  76.   return dosdate;
  77. }
  78.  
  79.  
  80.  
  81. char * _fast sc_time(union stamp_combo *sc,char *string)
  82. {
  83.   if (sc->msg_st.date.yr==0)
  84.     *string='\0';
  85.   else
  86.   {
  87.     sprintf(string,
  88.            "%2d %s %d %02d:%02d:%02d",
  89.            sc->msg_st.date.da,
  90.            months_ab[sc->msg_st.date.mo-1],
  91.            80+sc->msg_st.date.yr,
  92.            sc->msg_st.time.hh,
  93.            sc->msg_st.time.mm,
  94.            sc->msg_st.time.ss << 1);
  95.   }
  96.  
  97.   return string;
  98. }
  99.  
  100.