mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 05:15:41 +00:00
Fixed output of various date/time stuff ($D and $T in prompt, %DATE% and %TIME% variables, DATE /T and TIME /T commands) to be more compatible with Windows.
svn path=/trunk/; revision=40050
This commit is contained in:
parent
80c1384089
commit
6f8ec7004e
8 changed files with 80 additions and 82 deletions
|
@ -928,27 +928,12 @@ GetEnvVarOrSpecial ( LPCTSTR varName )
|
||||||
/* %TIME% */
|
/* %TIME% */
|
||||||
else if (_tcsicmp(varName,_T("time")) ==0)
|
else if (_tcsicmp(varName,_T("time")) ==0)
|
||||||
{
|
{
|
||||||
SYSTEMTIME t;
|
return GetTimeString();
|
||||||
if ( !GrowIfNecessary ( MAX_PATH, &ret, &retlen ) )
|
|
||||||
return NULL;
|
|
||||||
GetSystemTime(&t);
|
|
||||||
_sntprintf ( ret, retlen, _T("%02d%c%02d%c%02d%c%02d"),
|
|
||||||
t.wHour, cTimeSeparator, t.wMinute, cTimeSeparator,
|
|
||||||
t.wSecond, cDecimalSeparator, t.wMilliseconds / 10);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
/* %DATE% */
|
/* %DATE% */
|
||||||
else if (_tcsicmp(varName,_T("date")) ==0)
|
else if (_tcsicmp(varName,_T("date")) ==0)
|
||||||
{
|
{
|
||||||
|
return GetDateString();
|
||||||
if ( !GrowIfNecessary ( GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, NULL, 0), &ret, &retlen ) )
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
size = GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, ret, retlen);
|
|
||||||
|
|
||||||
if ( !size )
|
|
||||||
return NULL;
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* %RANDOM% */
|
/* %RANDOM% */
|
||||||
|
@ -1155,12 +1140,9 @@ GetEnhancedVar(TCHAR **pFormat, LPTSTR (*GetVar)(TCHAR, BOOL *))
|
||||||
FileTimeToLocalFileTime(&w32fd.ftLastWriteTime, &ft);
|
FileTimeToLocalFileTime(&w32fd.ftLastWriteTime, &ft);
|
||||||
FileTimeToSystemTime(&ft, &st);
|
FileTimeToSystemTime(&ft, &st);
|
||||||
|
|
||||||
/* TODO: This probably should be locale-dependent */
|
Out += FormatDate(Out, &st, TRUE);
|
||||||
Out += _stprintf(Out,
|
*Out++ = _T(' ');
|
||||||
_T("%02d/%02d/%04d %02d:%02d %cM "),
|
Out += FormatTime(Out, &st);
|
||||||
st.wMonth, st.wDay, st.wYear,
|
|
||||||
(st.wHour + 11) % 12 + 1, st.wMinute,
|
|
||||||
(st.wHour >= 12) ? _T('P') : _T('A'));
|
|
||||||
}
|
}
|
||||||
if (Modifiers & M_SIZE)
|
if (Modifiers & M_SIZE)
|
||||||
{
|
{
|
||||||
|
|
|
@ -191,6 +191,8 @@ INT CommandDelay (LPTSTR);
|
||||||
|
|
||||||
|
|
||||||
/* Prototypes for DIR.C */
|
/* Prototypes for DIR.C */
|
||||||
|
INT FormatDate (TCHAR *, LPSYSTEMTIME, BOOL);
|
||||||
|
INT FormatTime (TCHAR *, LPSYSTEMTIME);
|
||||||
INT CommandDir (LPTSTR);
|
INT CommandDir (LPTSTR);
|
||||||
|
|
||||||
|
|
||||||
|
@ -304,8 +306,8 @@ extern INT nNumberGroups;
|
||||||
|
|
||||||
|
|
||||||
VOID InitLocale (VOID);
|
VOID InitLocale (VOID);
|
||||||
VOID PrintDate (VOID);
|
LPTSTR GetDateString (VOID);
|
||||||
VOID PrintTime (VOID);
|
LPTSTR GetTimeString (VOID);
|
||||||
|
|
||||||
/* cache codepage */
|
/* cache codepage */
|
||||||
extern UINT InputCodePage;
|
extern UINT InputCodePage;
|
||||||
|
|
|
@ -205,7 +205,7 @@ INT cmd_date (LPTSTR param)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nDateString == -1)
|
if (nDateString == -1)
|
||||||
PrintDate ();
|
ConOutPrintf(_T("%s"), GetDateString());
|
||||||
|
|
||||||
if (!bPrompt)
|
if (!bPrompt)
|
||||||
{
|
{
|
||||||
|
|
|
@ -644,7 +644,6 @@ DirPrintFileDateTime(TCHAR *lpDate,
|
||||||
{
|
{
|
||||||
FILETIME ft;
|
FILETIME ft;
|
||||||
SYSTEMTIME dt;
|
SYSTEMTIME dt;
|
||||||
WORD wYear;
|
|
||||||
|
|
||||||
/* Select the right time field */
|
/* Select the right time field */
|
||||||
switch (lpFlags->stTimeField.eTimeField)
|
switch (lpFlags->stTimeField.eTimeField)
|
||||||
|
@ -668,44 +667,56 @@ DirPrintFileDateTime(TCHAR *lpDate,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FormatDate(lpDate, &dt, lpFlags->b4Digit);
|
||||||
|
FormatTime(lpTime, &dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
INT
|
||||||
|
FormatDate(TCHAR *lpDate, LPSYSTEMTIME dt, BOOL b4Digit)
|
||||||
|
{
|
||||||
/* Format date */
|
/* Format date */
|
||||||
wYear = (lpFlags->b4Digit) ? dt.wYear : dt.wYear%100;
|
WORD wYear = b4Digit ? dt->wYear : dt->wYear%100;
|
||||||
switch (nDateFormat)
|
switch (nDateFormat)
|
||||||
{
|
{
|
||||||
case 0: /* mmddyy */
|
case 0: /* mmddyy */
|
||||||
default:
|
default:
|
||||||
_stprintf(lpDate, _T("%02d%c%02d%c%0*d"),
|
return _stprintf(lpDate, _T("%02d%c%02d%c%0*d"),
|
||||||
dt.wMonth, cDateSeparator,
|
dt->wMonth, cDateSeparator,
|
||||||
dt.wDay, cDateSeparator,
|
dt->wDay, cDateSeparator,
|
||||||
lpFlags->b4Digit?4:2, wYear);
|
b4Digit?4:2, wYear);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: /* ddmmyy */
|
case 1: /* ddmmyy */
|
||||||
_stprintf(lpDate, _T("%02d%c%02d%c%0*d"),
|
return _stprintf(lpDate, _T("%02d%c%02d%c%0*d"),
|
||||||
dt.wDay, cDateSeparator, dt.wMonth,
|
dt->wDay, cDateSeparator, dt->wMonth,
|
||||||
cDateSeparator,lpFlags->b4Digit?4:2, wYear);
|
cDateSeparator, b4Digit?4:2, wYear);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: /* yymmdd */
|
case 2: /* yymmdd */
|
||||||
_stprintf(lpDate, _T("%0*d%c%02d%c%02d"),
|
return _stprintf(lpDate, _T("%0*d%c%02d%c%02d"),
|
||||||
lpFlags->b4Digit?4:2, wYear, cDateSeparator,
|
b4Digit?4:2, wYear, cDateSeparator,
|
||||||
dt.wMonth, cDateSeparator, dt.wDay);
|
dt->wMonth, cDateSeparator, dt->wDay);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
INT
|
||||||
|
FormatTime(TCHAR *lpTime, LPSYSTEMTIME dt)
|
||||||
|
{
|
||||||
/* Format Time */
|
/* Format Time */
|
||||||
switch (nTimeFormat)
|
switch (nTimeFormat)
|
||||||
{
|
{
|
||||||
case 0: /* 12 hour format */
|
case 0: /* 12 hour format */
|
||||||
default:
|
default:
|
||||||
_stprintf(lpTime,_T("%02d%c%02u%c"),
|
return _stprintf(lpTime,_T("%02d%c%02u%c"),
|
||||||
(dt.wHour == 0 ? 12 : (dt.wHour <= 12 ? dt.wHour : dt.wHour - 12)),
|
(dt->wHour == 0 ? 12 : (dt->wHour <= 12 ? dt->wHour : dt->wHour - 12)),
|
||||||
cTimeSeparator,
|
cTimeSeparator,
|
||||||
dt.wMinute, (dt.wHour <= 11 ? _T('a') : _T('p')));
|
dt->wMinute, (dt->wHour <= 11 ? _T('a') : _T('p')));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: /* 24 hour format */
|
case 1: /* 24 hour format */
|
||||||
_stprintf(lpTime, _T("%02d%c%02u"),
|
return _stprintf(lpTime, _T("%02d%c%02u"),
|
||||||
dt.wHour, cTimeSeparator, dt.wMinute);
|
dt->wHour, cTimeSeparator, dt->wMinute);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,27 +54,30 @@ VOID InitLocale (VOID)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return date string including weekday. Used for $D in prompt and %DATE% */
|
||||||
VOID PrintDate (VOID)
|
LPTSTR
|
||||||
|
GetDateString(VOID)
|
||||||
{
|
{
|
||||||
TCHAR szDateDay[32];
|
static TCHAR szDate[32];
|
||||||
TCHAR szDate[32];
|
SYSTEMTIME t;
|
||||||
|
INT len;
|
||||||
|
GetLocalTime(&t);
|
||||||
|
|
||||||
GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, _T("ddd"), szDateDay, sizeof (szDateDay));
|
len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &t, _T("ddd"), szDate, sizeof szDate);
|
||||||
|
szDate[len - 1] = _T(' ');
|
||||||
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL,szDate, sizeof (szDate));
|
FormatDate(&szDate[len], &t, TRUE);
|
||||||
ConOutPrintf(_T("%s %s"),szDateDay, szDate);
|
return szDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return time in hh:mm:ss.xx format. Used for $T in prompt and %TIME% */
|
||||||
VOID PrintTime (VOID)
|
LPTSTR
|
||||||
|
GetTimeString(VOID)
|
||||||
{
|
{
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
static TCHAR szTime[12];
|
||||||
SYSTEMTIME t;
|
SYSTEMTIME t;
|
||||||
GetLocalTime(&t);
|
GetLocalTime(&t);
|
||||||
|
_stprintf(szTime, _T("%02d%c%02d%c%02d%c%02d"),
|
||||||
LoadString(CMD_ModuleHandle, STRING_LOCALE_HELP1, szMsg, RC_STRING_MAX_SIZE);
|
t.wHour, cTimeSeparator, t.wMinute, cTimeSeparator,
|
||||||
ConOutPrintf(_T("%s: %02d%c%02d%c%02d%c%02d\n"), szMsg, t.wHour, cTimeSeparator,
|
t.wSecond, cDecimalSeparator, t.wMilliseconds / 10);
|
||||||
t.wMinute , cTimeSeparator,
|
return szTime;
|
||||||
t.wSecond , cDecimalSeparator, t.wMilliseconds );
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ VOID PrintPrompt(VOID)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('D'):
|
case _T('D'):
|
||||||
PrintDate ();
|
ConOutPrintf(_T("%s"), GetDateString());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('E'):
|
case _T('E'):
|
||||||
|
@ -137,12 +137,7 @@ VOID PrintPrompt(VOID)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('T'):
|
case _T('T'):
|
||||||
{
|
ConOutPrintf(_T("%s"), GetTimeString());
|
||||||
SYSTEMTIME t;
|
|
||||||
GetSystemTime(&t);
|
|
||||||
ConOutPrintf(_T("%02d%c%02d%c%02d%c%02d\n"),t.wHour, cTimeSeparator,t.wMinute , cTimeSeparator,
|
|
||||||
t.wSecond , cDecimalSeparator, t.wMilliseconds );
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('V'):
|
case _T('V'):
|
||||||
|
|
|
@ -134,7 +134,6 @@ INT cmd_time (LPTSTR param)
|
||||||
LPTSTR *arg;
|
LPTSTR *arg;
|
||||||
INT argc;
|
INT argc;
|
||||||
INT i;
|
INT i;
|
||||||
BOOL bPrompt = TRUE;
|
|
||||||
INT nTimeString = -1;
|
INT nTimeString = -1;
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
|
@ -152,19 +151,25 @@ INT cmd_time (LPTSTR param)
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
{
|
{
|
||||||
if (_tcsicmp (arg[i], _T("/t")) == 0)
|
if (_tcsicmp (arg[i], _T("/t")) == 0)
|
||||||
bPrompt = FALSE;
|
{
|
||||||
|
/* Display current time in short format */
|
||||||
|
SYSTEMTIME st;
|
||||||
|
TCHAR szTime[20];
|
||||||
|
GetLocalTime(&st);
|
||||||
|
FormatTime(szTime, &st);
|
||||||
|
ConOutPuts(szTime);
|
||||||
|
freep(arg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ((*arg[i] != _T('/')) && (nTimeString == -1))
|
if ((*arg[i] != _T('/')) && (nTimeString == -1))
|
||||||
nTimeString = i;
|
nTimeString = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nTimeString == -1)
|
if (nTimeString == -1)
|
||||||
PrintTime ();
|
|
||||||
|
|
||||||
if (!bPrompt)
|
|
||||||
{
|
{
|
||||||
freep (arg);
|
ConOutResPrintf(STRING_LOCALE_HELP1);
|
||||||
return 0;
|
ConOutPrintf(_T(": %s\n"), GetTimeString());
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
|
|
|
@ -153,7 +153,7 @@ INT CommandTimer (LPTSTR param)
|
||||||
cS=TRUE;
|
cS=TRUE;
|
||||||
|
|
||||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||||
PrintTime();
|
ConOutPuts(GetTimeString());
|
||||||
freep(p);
|
freep(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ INT CommandTimer (LPTSTR param)
|
||||||
if(cS)
|
if(cS)
|
||||||
{
|
{
|
||||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||||
PrintTime();
|
ConOutPuts(GetTimeString());
|
||||||
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
||||||
freep(p);
|
freep(p);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -172,7 +172,7 @@ INT CommandTimer (LPTSTR param)
|
||||||
cT=GetTickCount();
|
cT=GetTickCount();
|
||||||
cS=TRUE;
|
cS=TRUE;
|
||||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||||
PrintTime();
|
ConOutPuts(GetTimeString());
|
||||||
freep(p);
|
freep(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ INT CommandTimer (LPTSTR param)
|
||||||
{
|
{
|
||||||
cS=FALSE;
|
cS=FALSE;
|
||||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||||
PrintTime();
|
ConOutPuts(GetTimeString());
|
||||||
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
||||||
freep(p);
|
freep(p);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -192,7 +192,7 @@ INT CommandTimer (LPTSTR param)
|
||||||
cT=GetTickCount();
|
cT=GetTickCount();
|
||||||
cS=TRUE;
|
cS=TRUE;
|
||||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||||
PrintTime();
|
ConOutPuts(GetTimeString());
|
||||||
freep(p);
|
freep(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -204,13 +204,13 @@ INT CommandTimer (LPTSTR param)
|
||||||
{
|
{
|
||||||
cS=FALSE;
|
cS=FALSE;
|
||||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||||
PrintTime();
|
ConOutPuts(GetTimeString());
|
||||||
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
||||||
freep(p);
|
freep(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
||||||
PrintTime();
|
ConOutPuts(GetTimeString());
|
||||||
freep(p);
|
freep(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue