[PATCH 3/3] programs/cmd: Fix the output of date and time /t.
Francois Gouget
fgouget at codeweavers.com
Wed Mar 23 21:59:48 CDT 2022
They just output the date / time, without any explanatory text.
Furthermore time /t only returns the time down to the minute.
Signed-off-by: Francois Gouget <fgouget at free.fr>
---
Unlike echo %time%, though that's broken too in Wine.
---
programs/cmd/builtins.c | 19 ++++++++++++++-----
programs/cmd/tests/test_builtins.cmd | 7 +++++++
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 963a9eaf361..d8dfe732a44 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -3503,14 +3503,17 @@ void WCMD_setshow_date (void) {
if (!*param1) {
if (GetDateFormatW(LOCALE_USER_DEFAULT, 0, NULL, NULL, curdate, ARRAY_SIZE(curdate))) {
- WCMD_output (WCMD_LoadMessage(WCMD_CURRENTDATE), curdate);
if (wcsstr(quals, L"/T") == NULL) {
+ WCMD_output (WCMD_LoadMessage(WCMD_CURRENTDATE), curdate);
WCMD_output (WCMD_LoadMessage(WCMD_NEWDATE));
WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), buffer, ARRAY_SIZE(buffer), &count);
if (count > 2) {
WCMD_output_stderr (WCMD_LoadMessage(WCMD_NYI));
}
}
+ else {
+ WCMD_output (curdate);
+ }
}
else WCMD_print_error ();
}
@@ -4291,17 +4294,23 @@ void WCMD_setshow_time (void) {
if (!*param1) {
GetLocalTime(&st);
- if (GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, curtime, ARRAY_SIZE(curtime))) {
- WCMD_output (WCMD_LoadMessage(WCMD_CURRENTTIME), curtime);
- if (wcsstr(quals, L"/T") == NULL) {
+ if (wcsstr(quals, L"/T") == NULL) {
+ if (GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, curtime, ARRAY_SIZE(curtime))) {
+ WCMD_output (WCMD_LoadMessage(WCMD_CURRENTTIME), curtime);
WCMD_output (WCMD_LoadMessage(WCMD_NEWTIME));
WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), buffer, ARRAY_SIZE(buffer), &count);
if (count > 2) {
WCMD_output_stderr (WCMD_LoadMessage(WCMD_NYI));
}
}
+ else WCMD_print_error ();
+ }
+ else {
+ if (GetTimeFormatW(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, NULL, curtime, ARRAY_SIZE(curtime))) {
+ WCMD_output (curtime);
+ }
+ else WCMD_print_error ();
}
- else WCMD_print_error ();
}
else {
WCMD_output_stderr (WCMD_LoadMessage(WCMD_NYI));
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index d8150692b54..7d61589a4a9 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -1794,6 +1794,8 @@ echo Century=%date:~6,2%
set WINE_foo=%date:~9,1%
if not defined WINE_foo echo "%%date%% is too short"
rem But may be longer depending on locale
+for /f "usebackq tokens=*" %%i in (`date /t`) do set WINE_foo=%%i
+if not "%Wine_foo%"=="%date%" echo "date /t vs %%date%% mismatch"
set WINE_foo=%time:~7,1%
if not defined WINE_foo echo "No seconds in %%time%%"
@@ -1801,6 +1803,11 @@ set WINE_foo=%time:~10,1%
if not defined WINE_foo echo "No 1/100s in %%time%%"
set WINE_foo=%time:~11,1%
if defined WINE_foo echo "Found more time at the end of %%time%%"
+rem Make sure to avoid failures on minute ticks
+set WINE_before=%time:~0,5%
+for /f "usebackq tokens=*" %%i in (`time /t`) do set WINE_foo=%%i
+set WINE_after=%time:~0,5%
+if not "%WINE_foo%"=="%WINE_before%" if not "%WINE_foo%"=="%WINE_after%" echo "time /t vs %%time%% mismatch"
set WINE_foo=%random%
if %WINE_foo% equ %random% echo "%%random%% is not random"
--
2.30.2
More information about the wine-devel
mailing list