I want to get dates from [start_date, end_date].
For Example, [20220620, 20220622] should return std::vector<int32_t>{20220620, 20220621, 20220622}
my input's type is int.
I think there are several steps i should take:
- translate int into a time struct type(support arithmetic operation).
- for loop between [start, end]
the first step seems easy.
I tried:
std::tm make_tm(int32_t s) {
int32_t s_year = s / 10000; int32_t s_mon = s % 10000 / 100; int32_t s_day = s % 100;
std::tm st;
st.tm_year = s_year - 1900;
st.tm_mon = s_mon - 1;
st.tm_mday = s_day;
std::mktime(&st);
return st;
}
and std::tm
type supports add, i can get the next date by just add the st.tm_mday
.
but i cant find a good method to loop.
could you help on this, and is there any better methods can do this?