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.
33 #ifdef INCLUDE_CMD_DATE
43 static WORD awMonths[2][13] =
45 {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
46 {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
51 PrintDateString (VOID)
57 ConOutPrintf (_T("\nEnter new date (mm%cdd%cyyyy): "),
58 cDateSeparator, cDateSeparator);
62 ConOutPrintf (_T("\nEnter new date (dd%cmm%cyyyy): "),
63 cDateSeparator, cDateSeparator);
67 ConOutPrintf (_T("\nEnter new date (yyyy%cmm%cdd): "),
68 cDateSeparator, cDateSeparator);
75 ReadNumber (LPTSTR *s, LPWORD lpwValue)
79 while (_istdigit (**s))
81 *lpwValue = *lpwValue * 10 + **s - _T('0');
91 ReadSeparator (LPTSTR *s)
93 if (**s == _T('/') || **s == _T('-') || **s == cDateSeparator)
122 if (!ReadNumber (&p, &d.wMonth))
124 if (!ReadSeparator (&p))
126 if (!ReadNumber (&p, &d.wDay))
128 if (!ReadSeparator (&p))
130 if (!ReadNumber (&p, &d.wYear))
135 if (!ReadNumber (&p, &d.wDay))
137 if (!ReadSeparator (&p))
139 if (!ReadNumber (&p, &d.wMonth))
141 if (!ReadSeparator (&p))
143 if (!ReadNumber (&p, &d.wYear))
148 if (!ReadNumber (&p, &d.wYear))
150 if (!ReadSeparator (&p))
152 if (!ReadNumber (&p, &d.wMonth))
154 if (!ReadSeparator (&p))
156 if (!ReadNumber (&p, &d.wDay))
161 /* if only entered two digits: */
162 /* assume 2000's if value less than 80 */
163 /* assume 1900's if value greater or equal 80 */
167 d.wYear = 1900 + d.wYear;
169 d.wYear = 2000 + d.wYear;
172 leap = (!(d.wYear % 4) && (d.wYear % 100)) || !(d.wYear % 400);
174 if ((d.wMonth >= 1 && d.wMonth <= 12) &&
175 (d.wDay >= 1 && d.wDay <= awMonths[leap][d.wMonth]) &&
176 (d.wYear >= 1980 && d.wYear <= 2099))
186 INT cmd_date (LPTSTR cmd, LPTSTR param)
192 INT nDateString = -1;
194 if (!_tcsncmp (param, _T("/?"), 2))
196 ConOutPuts (_T("Displays or sets the date.\n\n"
197 "DATE [/T][date]\n\n"
198 " /T display only\n\n"
199 "Type DATE without parameters to display the current date setting and\n"
200 "a prompt for a new one. Press ENTER to keep the same date."));
204 /* build parameter array */
205 arg = split (param, &argc, FALSE);
207 /* check for options */
208 for (i = 0; i < argc; i++)
210 if (_tcsicmp (arg[i], _T("/t")) == 0)
212 if ((*arg[i] != _T('/')) && (nDateString == -1))
216 if (nDateString == -1)
225 if (nDateString == -1)
227 while (TRUE) /* forever loop */
234 DebugPrintf (_T("\'%s\'\n"), s);
236 while (*s && s[_tcslen (s) - 1] < _T(' '))
237 s[_tcslen (s) - 1] = _T('\0');
243 ConErrPuts (_T("Invalid date."));
248 if (ParseDate (arg[nDateString]))
253 ConErrPuts (_T("Invalid date."));