e2712366d854e809357be6145a27cfcd3979563e
2 * DATE.C - date internal command.
7 * 08 Jul 1998 (John P. Price)
10 * 20 Jul 1998 (John P. Price)
11 * corrected number of days for December from 30 to 31.
12 * (Thanx to Steffen Kaiser for bug report)
14 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
15 * added config.h include
17 * 29-Jul-1998 (Rob Lake)
18 * fixed stand-alone mode.
19 * Added Pacific C compatible dos_getdate functions
21 * 09-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
22 * Added locale support
24 * 23-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
25 * Unicode and redirection safe!
27 * 04-Feb-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
28 * Fixed date input bug.
31 #define WIN32_LEAN_AND_MEAN
35 #ifdef INCLUDE_CMD_DATE
45 static WORD awMonths
[2][13] =
47 {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
48 {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
64 ConOutPrintf (_T("Current date is: %s %02d%c%02d%c%04d\n"),
65 aszDayNames
[st
.wDayOfWeek
], st
.wMonth
, cDateSeparator
, st
.wDay
, cDateSeparator
, st
.wYear
);
69 ConOutPrintf (_T("Current date is: %s %02d%c%02d%c%04d\n"),
70 aszDayNames
[st
.wDayOfWeek
], st
.wDay
, cDateSeparator
, st
.wMonth
, cDateSeparator
, st
.wYear
);
74 ConOutPrintf (_T("Current date is: %s %04d%c%02d%c%02d\n"),
75 aszDayNames
[st
.wDayOfWeek
], st
.wYear
, cDateSeparator
, st
.wMonth
, cDateSeparator
, st
.wDay
);
81 GetDateFormat (LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, NULL
, NULL
,
82 szDate
, sizeof (szDate
));
83 ConOutPrintf (_T("Current date is: %s\n"), szDate
);
88 PrintDateString (VOID
)
94 ConOutPrintf (_T("Enter new date (mm%cdd%cyyyy): "),
95 cDateSeparator
, cDateSeparator
);
99 ConOutPrintf (_T("Enter new date (dd%cmm%cyyyy): "),
100 cDateSeparator
, cDateSeparator
);
104 ConOutPrintf (_T("Enter new date (yyyy%cmm%cdd): "),
105 cDateSeparator
, cDateSeparator
);
112 ReadNumber (LPTSTR
*s
, LPWORD lpwValue
)
116 while (_istdigit (**s
))
118 *lpwValue
= *lpwValue
* 10 + **s
- _T('0');
128 ReadSeparator (LPTSTR
*s
)
130 if (**s
== _T('/') || **s
== _T('-') || **s
== cDateSeparator
)
159 if (!ReadNumber (&p
, &d
.wMonth
))
161 if (!ReadSeparator (&p
))
163 if (!ReadNumber (&p
, &d
.wDay
))
165 if (!ReadSeparator (&p
))
167 if (!ReadNumber (&p
, &d
.wYear
))
172 if (!ReadNumber (&p
, &d
.wDay
))
174 if (!ReadSeparator (&p
))
176 if (!ReadNumber (&p
, &d
.wMonth
))
178 if (!ReadSeparator (&p
))
180 if (!ReadNumber (&p
, &d
.wYear
))
185 if (!ReadNumber (&p
, &d
.wYear
))
187 if (!ReadSeparator (&p
))
189 if (!ReadNumber (&p
, &d
.wMonth
))
191 if (!ReadSeparator (&p
))
193 if (!ReadNumber (&p
, &d
.wDay
))
198 /* if only entered two digits:
199 /* assume 2000's if value less than 80 */
200 /* assume 1900's if value greater or equal 80 */
204 d
.wYear
= 1900 + d
.wYear
;
206 d
.wYear
= 2000 + d
.wYear
;
209 leap
= (!(d
.wYear
% 4) && (d
.wYear
% 100)) || !(d
.wYear
% 400);
211 if ((d
.wMonth
>= 1 && d
.wMonth
<= 12) &&
212 (d
.wDay
>= 1 && d
.wDay
<= awMonths
[leap
][d
.wMonth
]) &&
213 (d
.wYear
>= 1980 && d
.wYear
<= 2099))
223 INT
cmd_date (LPTSTR cmd
, LPTSTR param
)
229 INT nDateString
= -1;
231 if (!_tcsncmp (param
, _T("/?"), 2))
233 ConOutPuts (_T("Displays or sets the date.\n\n"
234 "DATE [/T][date]\n\n"
235 " /T display only\n\n"
236 "Type DATE without parameters to display the current date setting and\n"
237 "a prompt for a new one. Press ENTER to keep the same date."));
241 /* build parameter array */
242 arg
= split (param
, &argc
);
244 /* check for options */
245 for (i
= 0; i
< argc
; i
++)
247 if (_tcsicmp (arg
[i
], _T("/t")) == 0)
249 if ((*arg
[i
] != _T('/')) && (nDateString
== -1))
253 if (nDateString
== -1)
262 if (nDateString
== -1)
264 while (TRUE
) /* forever loop */
271 DebugPrintf ("\'%s\'\n", s
);
273 while (*s
&& s
[_tcslen (s
) - 1] < ' ')
274 s
[_tcslen (s
) - 1] = '\0';
280 ConErrPuts ("Invalid date.");
285 if (ParseDate (arg
[nDateString
]))
290 ConErrPuts ("Invalid date.");