| 131 | |
| 132 | |
| 133 | ResultType YYYYMMDDToSystemTime(LPTSTR aYYYYMMDD, SYSTEMTIME &aSystemTime, bool aValidateTimeValues) |
| 134 | // Although aYYYYMMDD need not be terminated at the end of the YYYYMMDDHH24MISS string (as long as |
| 135 | // the string's capacity is at least 14), it should be terminated if only the leading part |
| 136 | // of the YYYYMMDDHH24MISS format is present. |
| 137 | // Caller must ensure that aYYYYMMDD is non-NULL. If the string's length is not an even number |
| 138 | // between 4 and 14 (inclusive), FAIL is returned. FAIL is also returned if aValidateTimeValues |
| 139 | // is true and some elements of aYYYYMMDD were invalid, or if the year is less than 1601 |
| 140 | // (Windows generally does not support earlier years). Otherwise OK is returned. |
| 141 | { |
| 142 | // sscanf() is avoided because it adds 2 KB to the compressed EXE size. |
| 143 | TCHAR temp[16]; |
| 144 | size_t length = _tcslen(aYYYYMMDD); // Use this rather than incrementing the pointer in case there are ever partial fields such as 20051 vs. 200501. |
| 145 | |
| 146 | tcslcpy(temp, aYYYYMMDD, 5); |
| 147 | aSystemTime.wYear = _ttoi(temp); |
| 148 | |
| 149 | if (length > 4) // It has a month component. |
| 150 | { |
| 151 | tcslcpy(temp, aYYYYMMDD + 4, 3); |
| 152 | aSystemTime.wMonth = _ttoi(temp); // Unlike "struct tm", SYSTEMTIME uses 1 for January, not 0. |
| 153 | // v1.0.48: Changed not to provide a default when month number is out-of-range. |
| 154 | // This allows callers like "if var is time" to properly detect badly-formatted dates. |
| 155 | } |
| 156 | else |
| 157 | aSystemTime.wMonth = 1; |
| 158 | |
| 159 | if (length > 6) // It has a day-of-month component. |
| 160 | { |
| 161 | tcslcpy(temp, aYYYYMMDD + 6, 3); |
| 162 | aSystemTime.wDay = _ttoi(temp); |
| 163 | } |
| 164 | else |
| 165 | aSystemTime.wDay = 1; |
| 166 | |
| 167 | if (length > 8) // It has an hour component. |
| 168 | { |
| 169 | tcslcpy(temp, aYYYYMMDD + 8, 3); |
| 170 | aSystemTime.wHour = _ttoi(temp); |
| 171 | } |
| 172 | else |
| 173 | aSystemTime.wHour = 0; // Midnight. |
| 174 | |
| 175 | if (length > 10) // It has a minutes component. |
| 176 | { |
| 177 | tcslcpy(temp, aYYYYMMDD + 10, 3); |
| 178 | aSystemTime.wMinute = _ttoi(temp); |
| 179 | } |
| 180 | else |
| 181 | aSystemTime.wMinute = 0; |
| 182 | |
| 183 | if (length > 12) // It has a seconds component. |
| 184 | { |
| 185 | tcslcpy(temp, aYYYYMMDD + 12, 3); |
| 186 | aSystemTime.wSecond = _ttoi(temp); |
| 187 | } |
| 188 | else |
| 189 | aSystemTime.wSecond = 0; |
| 190 |
no outgoing calls
no test coverage detected