Author: jmorlan
Date: Mon Mar 16 03:44:08 2009
New Revision: 40050
URL:
http://svn.reactos.org/svn/reactos?rev=40050&view=rev
Log:
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.
Modified:
trunk/reactos/base/shell/cmd/cmd.c
trunk/reactos/base/shell/cmd/cmd.h
trunk/reactos/base/shell/cmd/date.c
trunk/reactos/base/shell/cmd/dir.c
trunk/reactos/base/shell/cmd/locale.c
trunk/reactos/base/shell/cmd/prompt.c
trunk/reactos/base/shell/cmd/time.c
trunk/reactos/base/shell/cmd/timer.c
Modified: trunk/reactos/base/shell/cmd/cmd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=4…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] Mon Mar 16 03:44:08 2009
@@ -928,27 +928,12 @@
/* %TIME% */
else if (_tcsicmp(varName,_T("time")) ==0)
{
- SYSTEMTIME t;
- 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;
+ return GetTimeString();
}
/* %DATE% */
else if (_tcsicmp(varName,_T("date")) ==0)
{
-
- 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;
+ return GetDateString();
}
/* %RANDOM% */
@@ -1155,12 +1140,9 @@
FileTimeToLocalFileTime(&w32fd.ftLastWriteTime, &ft);
FileTimeToSystemTime(&ft, &st);
- /* TODO: This probably should be locale-dependent */
- Out += _stprintf(Out,
- _T("%02d/%02d/%04d %02d:%02d %cM "),
- st.wMonth, st.wDay, st.wYear,
- (st.wHour + 11) % 12 + 1, st.wMinute,
- (st.wHour >= 12) ? _T('P') : _T('A'));
+ Out += FormatDate(Out, &st, TRUE);
+ *Out++ = _T(' ');
+ Out += FormatTime(Out, &st);
}
if (Modifiers & M_SIZE)
{
Modified: trunk/reactos/base/shell/cmd/cmd.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.h?rev=4…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] Mon Mar 16 03:44:08 2009
@@ -191,6 +191,8 @@
/* Prototypes for DIR.C */
+INT FormatDate (TCHAR *, LPSYSTEMTIME, BOOL);
+INT FormatTime (TCHAR *, LPSYSTEMTIME);
INT CommandDir (LPTSTR);
@@ -304,8 +306,8 @@
VOID InitLocale (VOID);
-VOID PrintDate (VOID);
-VOID PrintTime (VOID);
+LPTSTR GetDateString (VOID);
+LPTSTR GetTimeString (VOID);
/* cache codepage */
extern UINT InputCodePage;
Modified: trunk/reactos/base/shell/cmd/date.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/date.c?rev=…
==============================================================================
--- trunk/reactos/base/shell/cmd/date.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/date.c [iso-8859-1] Mon Mar 16 03:44:08 2009
@@ -205,7 +205,7 @@
}
if (nDateString == -1)
- PrintDate ();
+ ConOutPrintf(_T("%s"), GetDateString());
if (!bPrompt)
{
Modified: trunk/reactos/base/shell/cmd/dir.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/dir.c?rev=4…
==============================================================================
--- trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] Mon Mar 16 03:44:08 2009
@@ -644,7 +644,6 @@
{
FILETIME ft;
SYSTEMTIME dt;
- WORD wYear;
/* Select the right time field */
switch (lpFlags->stTimeField.eTimeField)
@@ -668,44 +667,56 @@
break;
}
+ FormatDate(lpDate, &dt, lpFlags->b4Digit);
+ FormatTime(lpTime, &dt);
+}
+
+INT
+FormatDate(TCHAR *lpDate, LPSYSTEMTIME dt, BOOL b4Digit)
+{
/* Format date */
- wYear = (lpFlags->b4Digit) ? dt.wYear : dt.wYear%100;
+ WORD wYear = b4Digit ? dt->wYear : dt->wYear%100;
switch (nDateFormat)
{
case 0: /* mmddyy */
default:
- _stprintf(lpDate, _T("%02d%c%02d%c%0*d"),
- dt.wMonth, cDateSeparator,
- dt.wDay, cDateSeparator,
- lpFlags->b4Digit?4:2, wYear);
+ return _stprintf(lpDate, _T("%02d%c%02d%c%0*d"),
+ dt->wMonth, cDateSeparator,
+ dt->wDay, cDateSeparator,
+ b4Digit?4:2, wYear);
break;
case 1: /* ddmmyy */
- _stprintf(lpDate, _T("%02d%c%02d%c%0*d"),
- dt.wDay, cDateSeparator, dt.wMonth,
- cDateSeparator,lpFlags->b4Digit?4:2, wYear);
+ return _stprintf(lpDate, _T("%02d%c%02d%c%0*d"),
+ dt->wDay, cDateSeparator, dt->wMonth,
+ cDateSeparator, b4Digit?4:2, wYear);
break;
case 2: /* yymmdd */
- _stprintf(lpDate, _T("%0*d%c%02d%c%02d"),
- lpFlags->b4Digit?4:2, wYear, cDateSeparator,
- dt.wMonth, cDateSeparator, dt.wDay);
+ return _stprintf(lpDate, _T("%0*d%c%02d%c%02d"),
+ b4Digit?4:2, wYear, cDateSeparator,
+ dt->wMonth, cDateSeparator, dt->wDay);
break;
}
+}
+
+INT
+FormatTime(TCHAR *lpTime, LPSYSTEMTIME dt)
+{
/* Format Time */
switch (nTimeFormat)
{
case 0: /* 12 hour format */
default:
- _stprintf(lpTime,_T("%02d%c%02u%c"),
- (dt.wHour == 0 ? 12 : (dt.wHour <= 12 ? dt.wHour : dt.wHour - 12)),
+ return _stprintf(lpTime,_T("%02d%c%02u%c"),
+ (dt->wHour == 0 ? 12 : (dt->wHour <= 12 ? dt->wHour : dt->wHour -
12)),
cTimeSeparator,
- dt.wMinute, (dt.wHour <= 11 ? _T('a') : _T('p')));
+ dt->wMinute, (dt->wHour <= 11 ? _T('a') : _T('p')));
break;
case 1: /* 24 hour format */
- _stprintf(lpTime, _T("%02d%c%02u"),
- dt.wHour, cTimeSeparator, dt.wMinute);
+ return _stprintf(lpTime, _T("%02d%c%02u"),
+ dt->wHour, cTimeSeparator, dt->wMinute);
break;
}
}
Modified: trunk/reactos/base/shell/cmd/locale.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/locale.c?re…
==============================================================================
--- trunk/reactos/base/shell/cmd/locale.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/locale.c [iso-8859-1] Mon Mar 16 03:44:08 2009
@@ -54,27 +54,30 @@
#endif
}
+/* Return date string including weekday. Used for $D in prompt and %DATE% */
+LPTSTR
+GetDateString(VOID)
+{
+ static TCHAR szDate[32];
+ SYSTEMTIME t;
+ INT len;
+ GetLocalTime(&t);
-VOID PrintDate (VOID)
-{
- TCHAR szDateDay[32];
- TCHAR szDate[32];
-
- GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, _T("ddd"), szDateDay, sizeof
(szDateDay));
-
- GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL,szDate, sizeof (szDate));
- ConOutPrintf(_T("%s %s"),szDateDay, szDate);
+ len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &t, _T("ddd"), szDate, sizeof
szDate);
+ szDate[len - 1] = _T(' ');
+ FormatDate(&szDate[len], &t, TRUE);
+ return szDate;
}
-
-VOID PrintTime (VOID)
+/* Return time in hh:mm:ss.xx format. Used for $T in prompt and %TIME% */
+LPTSTR
+GetTimeString(VOID)
{
- TCHAR szMsg[RC_STRING_MAX_SIZE];
- SYSTEMTIME t;
- GetLocalTime(&t);
-
- LoadString(CMD_ModuleHandle, STRING_LOCALE_HELP1, szMsg, RC_STRING_MAX_SIZE);
- ConOutPrintf(_T("%s: %02d%c%02d%c%02d%c%02d\n"), szMsg, t.wHour,
cTimeSeparator,
- t.wMinute , cTimeSeparator,
- t.wSecond , cDecimalSeparator, t.wMilliseconds );
+ static TCHAR szTime[12];
+ SYSTEMTIME t;
+ GetLocalTime(&t);
+ _stprintf(szTime, _T("%02d%c%02d%c%02d%c%02d"),
+ t.wHour, cTimeSeparator, t.wMinute, cTimeSeparator,
+ t.wSecond, cDecimalSeparator, t.wMilliseconds / 10);
+ return szTime;
}
Modified: trunk/reactos/base/shell/cmd/prompt.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/prompt.c?re…
==============================================================================
--- trunk/reactos/base/shell/cmd/prompt.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/prompt.c [iso-8859-1] Mon Mar 16 03:44:08 2009
@@ -87,7 +87,7 @@
break;
case _T('D'):
- PrintDate ();
+ ConOutPrintf(_T("%s"), GetDateString());
break;
case _T('E'):
@@ -137,12 +137,7 @@
break;
case _T('T'):
- {
- 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 );
- }
+ ConOutPrintf(_T("%s"), GetTimeString());
break;
case _T('V'):
Modified: trunk/reactos/base/shell/cmd/time.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/time.c?rev=…
==============================================================================
--- trunk/reactos/base/shell/cmd/time.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/time.c [iso-8859-1] Mon Mar 16 03:44:08 2009
@@ -134,7 +134,6 @@
LPTSTR *arg;
INT argc;
INT i;
- BOOL bPrompt = TRUE;
INT nTimeString = -1;
if (!_tcsncmp (param, _T("/?"), 2))
@@ -152,19 +151,25 @@
for (i = 0; i < argc; i++)
{
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))
nTimeString = i;
}
if (nTimeString == -1)
- PrintTime ();
-
- if (!bPrompt)
- {
- freep (arg);
- return 0;
+ {
+ ConOutResPrintf(STRING_LOCALE_HELP1);
+ ConOutPrintf(_T(": %s\n"), GetTimeString());
}
while (1)
Modified: trunk/reactos/base/shell/cmd/timer.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/timer.c?rev…
==============================================================================
--- trunk/reactos/base/shell/cmd/timer.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/timer.c [iso-8859-1] Mon Mar 16 03:44:08 2009
@@ -153,7 +153,7 @@
cS=TRUE;
ConOutResPrintf
(STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
- PrintTime();
+ ConOutPuts(GetTimeString());
freep(p);
return 0;
}
@@ -163,7 +163,7 @@
if(cS)
{
ConOutResPrintf
(STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
- PrintTime();
+ ConOutPuts(GetTimeString());
PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p);
return 0;
@@ -172,7 +172,7 @@
cT=GetTickCount();
cS=TRUE;
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
- PrintTime();
+ ConOutPuts(GetTimeString());
freep(p);
return 0;
}
@@ -183,7 +183,7 @@
{
cS=FALSE;
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
- PrintTime();
+ ConOutPuts(GetTimeString());
PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p);
return 0;
@@ -192,7 +192,7 @@
cT=GetTickCount();
cS=TRUE;
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
- PrintTime();
+ ConOutPuts(GetTimeString());
freep(p);
return 0;
}
@@ -204,13 +204,13 @@
{
cS=FALSE;
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
- PrintTime();
+ ConOutPuts(GetTimeString());
PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p);
return 0;
}
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
- PrintTime();
+ ConOutPuts(GetTimeString());
freep(p);
return 0;
}