home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / time.exe / TIMEDATE.C < prev    next >
Text File  |  1995-01-09  |  4KB  |  151 lines

  1. /****************************************************************************
  2. ** DISCLAIMER
  3. **
  4. ** Novell, Inc. makes no representations or warranties with respect to
  5. ** any NetWare software, and specifically disclaims any express or
  6. ** implied warranties of merchantability, title, or fitness for a
  7. ** particular purpose.
  8. **
  9. ** Distribution of any NetWare software is forbidden without the
  10. ** express written consent of Novell, Inc.  Further, Novell reserves
  11. ** the right to discontinue distribution of any NetWare software.
  12. **
  13. ** Novell is not responsible for lost profits or revenue, loss of use
  14. ** of the software, loss of data, costs of re-creating lost data, the
  15. ** cost of any substitute equipment or program, or claims by any party
  16. ** other than you.  Novell strongly recommends a backup be made before
  17. ** any software is installed.   Technical support for this software
  18. ** may be provided at the discretion of Novell.
  19. *****************************************************************************
  20. **
  21. ** File:   DateTime.c
  22. **
  23. ** Desc:   Example program of how to use NWUnpackDateTime() and NWPackDateTime()
  24. **
  25. **         
  26. ** Parameter descriptions:    > input
  27. **                            < output
  28. **
  29. **
  30. ** Netware API Calls:     
  31. **
  32. **
  33. ** Programmers:
  34. ** Ini   Who                Firm
  35. ** ------------------------------------------------------------------
  36. ** ARM   A. Ray Maxwell     Novell Developer Support.
  37. **
  38. ** History:
  39. **
  40. ** ------------------------------------------------------------------
  41. ** 07-29-94   ARM   First code.    
  42. */
  43.  
  44. /****************************************************************************
  45. **   Include headers, macros, function prototypes, etc.
  46. */
  47.    
  48.  
  49.    /*------------------------------------------------------------------
  50.    **   ANSI
  51.    */
  52.    #include <stdio.h>       /* printf()          */
  53.    #include <stdlib.h>      /* exit()            */
  54.    #include <string.h>      /* strcpy() strupr() */
  55.    #include <dos.h>        /* getdate() gettime() */
  56.   
  57.    /*------------------------------------------------------------------
  58.    **   NetWare
  59.    */
  60.    #define  NWDOS
  61.    #include <nwcalls.h>
  62.  
  63.  
  64.  
  65.    /*------------------------------------------------------------------
  66.    **   Prototypes
  67.    */
  68.  
  69.  
  70.    /*-------------------------------------------------------------------
  71.    ** Day parameters.  The bit breakdown on the unsigned wr_date in the
  72.    ** dos.h struct find_t.  two bytes in the following format
  73.    **       YYYYYYYMMMMDDDDD    They are masked with the following defines
  74.    **          7    4   5
  75.    **  The year is figured from 1980.  Thus the 80 for YRSTANDARD.
  76.    */
  77.    #define DAY        0x001F  
  78.    #define MONTH      0x01E0
  79.    #define YEAR       0xFE00
  80.    #define YRSTANDARD 80
  81.    
  82.    /*-------------------------------------------------------------------
  83.    ** Time parameters.  This is the bit breadown of wr_time.
  84.    **       HHHHHMMMMMMSSSSS  They are masked with the following defines.
  85.    **         5     6    5    
  86.    */
  87.    #define MINUTES 0x07E0
  88.    #define SECONDS 0x001F
  89.  
  90.  
  91. /****************************************************************************
  92. ** Print routine
  93. */
  94. void main()
  95. {
  96.    struct date d;
  97.    struct time t;
  98.    NW_DATE  nwd;
  99.    NW_TIME  nwt;
  100.    DWORD packedtime;
  101.    WORD timebytes;
  102.    WORD datebytes;
  103.  
  104.    getdate(&d);
  105.    gettime(&t);
  106.  
  107.    printf("Date and time before packing > %d/%d/%d   %d:%d:%d\n",
  108.           d.da_mon,
  109.           d.da_day,
  110.           d.da_year,
  111.           t.ti_hour,
  112.           t.ti_min,
  113.           t.ti_sec
  114.          );
  115.  
  116.    nwd.day   = d.da_day;
  117.    nwd.month = d.da_mon;
  118.    nwd.year  = d.da_year;
  119.  
  120.    nwt.hours   = t.ti_hour;
  121.    nwt.minutes = t.ti_min;
  122.    nwt.seconds = t.ti_sec;
  123.  
  124.    packedtime=NWPackDateTime(&nwd,&nwt);
  125.  
  126.    timebytes = (WORD)packedtime;
  127.    datebytes = packedtime>>16;
  128.  
  129. printf("Date and time after packing > %2d/%2d/%2d   %2d:%2d:%2d\n",
  130.          (datebytes & MONTH) >> 5,
  131.          (datebytes & DAY),
  132.          (datebytes >> 9)+YRSTANDARD,
  133.          (timebytes >> 11),
  134.          (timebytes & MINUTES) >> 5,
  135.          (timebytes & SECONDS) * 2
  136.          );
  137.  
  138.    NWUnpackDateTime(packedtime,&nwd,&nwt);
  139.  
  140.    printf("Date and time after unpacking > %d/%d/%d   %d:%d:%d\n",
  141.            nwd.month,
  142.            nwd.day,
  143.            nwd.year,
  144.            nwt.hours,   
  145.            nwt.minutes, 
  146.            nwt.seconds
  147.            );
  148.  
  149.  
  150. }
  151.