CPP: Add another test case based on a real world case.

This commit is contained in:
Geoffrey White 2019-06-21 17:43:17 +01:00
Родитель b1f6294083
Коммит cff3f9bdaf
2 изменённых файлов: 24 добавлений и 0 удалений

Просмотреть файл

@ -1,2 +1,5 @@
| test.cpp:173:29:173:38 | qwLongTime | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:170:2:170:47 | ... += ... | ... += ... | test.cpp:173:29:173:38 | qwLongTime | qwLongTime |
| test.cpp:174:30:174:39 | qwLongTime | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:170:2:170:47 | ... += ... | ... += ... | test.cpp:174:30:174:39 | qwLongTime | qwLongTime |
| test.cpp:193:15:193:18 | days | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:193:15:193:18 | days | days | test.cpp:193:15:193:18 | days | days |
| test.cpp:193:15:193:24 | ... / ... | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:193:15:193:24 | ... / ... | ... / ... | test.cpp:193:15:193:24 | ... / ... | ... / ... |
| test.cpp:193:22:193:24 | 365 | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:193:22:193:24 | 365 | 365 | test.cpp:193:22:193:24 | 365 | 365 |

Просмотреть файл

@ -176,3 +176,24 @@ void antipattern2()
// convert back to SYSTEMTIME for display or other usage
FileTimeToSystemTime(&ft, &st);
}
time_t mktime(struct tm *timeptr);
struct tm *gmtime(const time_t *timer);
time_t mkTime(int days)
{
struct tm tm;
time_t t;
tm.tm_sec = 0;
tm.tm_min = 0;
tm.tm_hour = 0;
tm.tm_mday = 0;
tm.tm_mon = 0;
tm.tm_year = days / 365; // BAD
// ...
t = mktime(&tm); // convert tm -> time_t
return t;
}