| 133 | } |
| 134 | |
| 135 | uint32_t calcDays(Date date) |
| 136 | { |
| 137 | constexpr auto kBaseYear = 1800; |
| 138 | constexpr auto kDaysInYear = 365; |
| 139 | |
| 140 | // adds years (365 for each year + 1 for leap years) |
| 141 | auto yearDiff = date.year - kBaseYear; |
| 142 | uint32_t dayCount = (yearDiff * kDaysInYear) + (yearDiff / 4); |
| 143 | |
| 144 | // add months |
| 145 | for (int month = 0; month < static_cast<uint8_t>(date.month); ++month) |
| 146 | { |
| 147 | dayCount += getMonthTotalDay(date.year, static_cast<MonthId>(month)); |
| 148 | } |
| 149 | |
| 150 | // add days |
| 151 | dayCount += date.day; |
| 152 | |
| 153 | return dayCount; |
| 154 | } |
| 155 | |
| 156 | static std::pair<MonthId, uint8_t> getMonthDay(int32_t dayOfYear) |
| 157 | { |
no test coverage detected