(examples are in zig, but I guess this is a general noob algorithmic question)
Let’s say we have a date
const Date = struct {
year: u16,
month: u4, //Jan=1,Dec=12
day: u5,
};
And something is supposed to happen at the regular intervals (aka every y
years, m
months and d
days)
const Interval = struct {
years: i16,
years_offset: i16,
months: i16,
months_offset: i16,
days: i16,
days_offset: i16,
};
note that months and days may be not restricted. I could say something should happend eveny 5 years, 23 months and 374 days, for example.
When determening a next date, let’s say days are shifted first (so we need to take into accound numbers of days in starting months), then months and years are shifted without changing the day.
If I have a date that may be not aligned to the interval, how do I get a previous/next date?
(note: Date
does have shiftDays
/shiftMonths
/shiftYears
methods).