2 * TIME.C - time internal command.
7 * 07/08/1998 (John P. Price)
10 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
11 * added config.h include
13 * 09-Jan-1999 (Eric Kohl)
14 * Added locale support.
16 * 19-Jan-1999 (Eric Kohl)
17 * Unicode and redirection safe!
20 * 04-Feb-1999 (Eric Kohl)
21 * Fixed time input bug.
23 * 30-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
24 * Remove all hardcoded strings in En.rc.
29 #ifdef INCLUDE_CMD_TIME
32 static BOOL
ParseTime (LPTSTR s
)
51 t
.wHour
= t
.wHour
* 10 + *p
- _T('0');
59 if (*p
!= cTimeSeparator
)
68 t
.wMinute
= t
.wMinute
* 10 + *p
- _T('0');
76 if (*p
!= cTimeSeparator
)
85 t
.wSecond
= t
.wSecond
* 10 + *p
- _T('0');
92 // get decimal separator
93 if (*p
== cDecimalSeparator
)
100 while (_istdigit(*p
))
102 // t.wMilliseconds = t.wMilliseconds * 10 + *p - _T('0');
105 // t.wMilliseconds *= 10;
109 /* special case: 12 hour format */
110 if (nTimeFormat
== 0)
112 if (_totupper(*s
) == _T('P'))
117 if ((_totupper(*s
) == _T('A')) && (t
.wHour
== 12))
123 if (t
.wHour
> 23 || t
.wMinute
> 60 || t
.wSecond
> 60 || t
.wMilliseconds
> 999)
132 INT
cmd_time (LPTSTR param
)
137 INT nTimeString
= -1;
139 if (!_tcsncmp (param
, _T("/?"), 2))
141 ConOutResPaging(TRUE
,STRING_TIME_HELP1
);
147 /* build parameter array */
148 arg
= split (param
, &argc
, FALSE
, FALSE
);
150 /* check for options */
151 for (i
= 0; i
< argc
; i
++)
153 if (_tcsicmp (arg
[i
], _T("/t")) == 0)
155 /* Display current time in short format */
159 FormatTime(szTime
, &st
);
165 if ((*arg
[i
] != _T('/')) && (nTimeString
== -1))
169 if (nTimeString
== -1)
171 ConOutResPrintf(STRING_LOCALE_HELP1
);
172 ConOutPrintf(_T(": %s\n"), GetTimeString());
177 if (nTimeString
== -1)
181 ConOutResPuts(STRING_TIME_HELP2
);
185 TRACE ("\'%s\'\n", debugstr_aw(s
));
187 while (*s
&& s
[_tcslen (s
) - 1] < _T(' '))
188 s
[_tcslen(s
) - 1] = _T('\0');
198 if (ParseTime (arg
[nTimeString
]))
204 /* force input the next time around. */
208 ConErrResPuts(STRING_TIME_ERROR1
);