home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
NOTEPAD2.ZIP
/
NPDATE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-08
|
4KB
|
120 lines
/***************************************************************************\
* npdate.c - notepad date/time handling
*
* Created by Microsoft Corporation, 1989:
\***************************************************************************/
#define INCL_WIN
#define INCL_BASE
#include <os2.h>
#include <stdio.h>
#include "notepad.h"
static BOOL f24HourFormat;
static USHORT fsDateFmt;
static CHAR szTimeSep[2];
static CHAR szDateSep[2];
static CHAR szAM[4];
static CHAR szPM[4];
PSZ fmtDateTime(PSZ buff)
{
DATETIME dt;
COUNTRYINFO cifo;
COUNTRYCODE ccode;
USHORT country;
BOOL fDOS;
USHORT len;
char dtbuff[10], tmbuff[12];
/* Get current time */
DosGetDateTime((PDATETIME)&dt);
/* Get the DOS country info in case we can't get the OS2.INI info */
ccode.country = ccode.codepage = 0;
fDOS = !(DosGetCtryInfo(sizeof(cifo),
(PCOUNTRYCODE)&ccode,
(PCOUNTRYINFO)&cifo,
(PUSHORT)&len));
country = fDOS ? cifo.country : 1; /* default to US */
/* Get the OS2.INI country info */
f24HourFormat = (WinQueryProfileInt(hab,
(PSZ)"PM_National",
(PSZ)"iTime",
fDOS? (SHORT)cifo.fsTimeFmt : 0));
fsDateFmt = WinQueryProfileInt(hab,
(PSZ)"PM_National",
(PSZ)"iDate",
fDOS? (SHORT)cifo.fsDateFmt : 0);
WinQueryProfileString(hab,
(PSZ)"PM_National",
(PSZ)"sDate",
(fDOS?(PSZ)cifo.szDateSeparator:(PSZ)"/"),
(PSZ)szDateSep,
2);
WinQueryProfileString(hab,
(PSZ)"PM_National",
(PSZ)"sTime",
(fDOS?(PSZ)cifo.szTimeSeparator:(PSZ)"/"),
(PSZ)szTimeSep,
2);
WinQueryProfileString(hab,
(PSZ)"PM_National",
(PSZ)"s1159",
((country == 1)
? (PSZ)"AM"
: (PSZ)""),
(PSZ)szAM,
4);
WinQueryProfileString(hab,
(PSZ)"PM_National",
(PSZ)"s2359",
((country == 1)
? (PSZ)"PM"
: (PSZ)""),
(PSZ)szPM,
4);
/* format the date according to country info */
if (fsDateFmt == 0)
sprintf(dtbuff,"%2d%s%02d%s%02d",dt.month,
szDateSep, dt.day,
szDateSep, (dt.year % 100));
else if (fsDateFmt == 1)
sprintf(dtbuff,"%2d%s%02d%s%02d",dt.day,
szDateSep, dt.month,
szDateSep, (dt.year % 100));
else
sprintf(dtbuff,"%02d%s%02d%s%02d", (dt.year % 100),
szDateSep, dt.month,
szDateSep, dt.day);
/* format the time according to country info */
if (f24HourFormat)
sprintf(tmbuff,"%2d%s%02d%s%02d", dt.hours,
szTimeSep, dt.minutes,
szTimeSep, dt.seconds);
else if ((dt.hours%12) == 0)
sprintf(tmbuff,"%2d%s%02d%s%02d %s", 12,
szTimeSep, dt.minutes,
szTimeSep, dt.seconds,
(dt.hours<12)?szAM:szPM);
else
sprintf(tmbuff,"%2d%s%02d%s%02d %s", dt.hours%12,
szTimeSep, dt.minutes,
szTimeSep, dt.seconds,
(dt.hours<12)?szAM:szPM);
sprintf(buff, "%s %s", dtbuff, tmbuff);
return(buff);
}