home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / NOTEPAD2.ZIP / NPDATE.C < prev    next >
C/C++ Source or Header  |  1989-02-08  |  4KB  |  120 lines

  1. /***************************************************************************\
  2. * npdate.c - notepad date/time handling
  3. *
  4. * Created by Microsoft Corporation, 1989:
  5. \***************************************************************************/
  6.  
  7. #define INCL_WIN
  8. #define INCL_BASE
  9. #include <os2.h>
  10. #include <stdio.h>
  11. #include "notepad.h"
  12.  
  13. static BOOL f24HourFormat;
  14. static USHORT fsDateFmt;
  15. static CHAR szTimeSep[2];
  16. static CHAR szDateSep[2];
  17. static CHAR szAM[4];
  18. static CHAR szPM[4];
  19.  
  20. PSZ fmtDateTime(PSZ buff)
  21. {
  22.         DATETIME dt;
  23.         COUNTRYINFO cifo;
  24.         COUNTRYCODE ccode;
  25.         USHORT country;
  26.         BOOL fDOS;
  27.         USHORT len;
  28.         char dtbuff[10], tmbuff[12];
  29.  
  30.         /* Get current time */
  31.         DosGetDateTime((PDATETIME)&dt);
  32.  
  33.         /* Get the DOS country info in case we can't get the OS2.INI info */
  34.         ccode.country = ccode.codepage = 0;
  35.         fDOS = !(DosGetCtryInfo(sizeof(cifo),
  36.                 (PCOUNTRYCODE)&ccode,
  37.                 (PCOUNTRYINFO)&cifo,
  38.                 (PUSHORT)&len));
  39.         country = fDOS ? cifo.country : 1;      /* default to US */
  40.  
  41.         /* Get the OS2.INI country info */
  42.         f24HourFormat = (WinQueryProfileInt(hab,
  43.                                 (PSZ)"PM_National",
  44.                                 (PSZ)"iTime",
  45.                                 fDOS? (SHORT)cifo.fsTimeFmt : 0));
  46.  
  47.         fsDateFmt = WinQueryProfileInt(hab,
  48.                                 (PSZ)"PM_National",
  49.                                 (PSZ)"iDate",
  50.                                 fDOS? (SHORT)cifo.fsDateFmt : 0);
  51.  
  52.         WinQueryProfileString(hab,
  53.                         (PSZ)"PM_National",
  54.                         (PSZ)"sDate",
  55.                         (fDOS?(PSZ)cifo.szDateSeparator:(PSZ)"/"),
  56.                         (PSZ)szDateSep,
  57.                         2);
  58.  
  59.         WinQueryProfileString(hab,
  60.                         (PSZ)"PM_National",
  61.                         (PSZ)"sTime",
  62.                         (fDOS?(PSZ)cifo.szTimeSeparator:(PSZ)"/"),
  63.                         (PSZ)szTimeSep,
  64.                         2);
  65.  
  66.         WinQueryProfileString(hab,
  67.                         (PSZ)"PM_National",
  68.                         (PSZ)"s1159",
  69.                         ((country == 1)
  70.                           ? (PSZ)"AM"
  71.                           : (PSZ)""),
  72.                         (PSZ)szAM,
  73.                         4);
  74.  
  75.         WinQueryProfileString(hab,
  76.                         (PSZ)"PM_National",
  77.                         (PSZ)"s2359",
  78.                         ((country == 1)
  79.                           ? (PSZ)"PM"
  80.                           : (PSZ)""),
  81.                         (PSZ)szPM,
  82.                         4);
  83.  
  84.  
  85.         /* format the date according to country info */
  86.         if (fsDateFmt == 0)
  87.                 sprintf(dtbuff,"%2d%s%02d%s%02d",dt.month,
  88.                         szDateSep, dt.day,
  89.                         szDateSep, (dt.year % 100));
  90.         else if (fsDateFmt == 1)
  91.                 sprintf(dtbuff,"%2d%s%02d%s%02d",dt.day,
  92.                         szDateSep, dt.month,
  93.                         szDateSep, (dt.year % 100));
  94.  
  95.         else
  96.                 sprintf(dtbuff,"%02d%s%02d%s%02d", (dt.year % 100),
  97.                         szDateSep, dt.month,
  98.                         szDateSep, dt.day);
  99.  
  100.         /* format the time according to country info */
  101.         if (f24HourFormat)
  102.                 sprintf(tmbuff,"%2d%s%02d%s%02d", dt.hours,
  103.                         szTimeSep, dt.minutes,
  104.                         szTimeSep, dt.seconds);
  105.         else if ((dt.hours%12) == 0)
  106.                 sprintf(tmbuff,"%2d%s%02d%s%02d %s", 12,
  107.                         szTimeSep, dt.minutes,
  108.                         szTimeSep, dt.seconds,
  109.                         (dt.hours<12)?szAM:szPM);
  110.         else
  111.                 sprintf(tmbuff,"%2d%s%02d%s%02d %s", dt.hours%12,
  112.                         szTimeSep, dt.minutes,
  113.                         szTimeSep, dt.seconds,
  114.                         (dt.hours<12)?szAM:szPM);
  115.  
  116.         sprintf(buff, "%s %s", dtbuff, tmbuff);
  117.  
  118.         return(buff);
  119. }
  120.