MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / calcDate

Function calcDate

src/OpenLoco/src/Date.cpp:100–133  ·  view source on GitHub ↗

0x00495C65 eax: totalDays returns: eax: year ebx: month edx: day

Source from the content-addressed store, hash-verified

98 // ebx: month
99 // edx: day
100 Date calcDate(const uint32_t totalDays)
101 {
102 constexpr auto kBaseYear = 1800;
103 constexpr auto kDaysInYear = 365;
104 constexpr auto kDaysInOlympiad = (365 * 4) + 1; // Useful because the calendar that Loco uses (Julian) has a 4-year cycle.
105 constexpr auto kFeb29 = 31 + 28;
106
107 int32_t years = ((totalDays / kDaysInOlympiad) & 0xFFFF) * 4;
108 int32_t day = totalDays % kDaysInOlympiad;
109
110 // Count the years and add an extra day for when there isn't leap year
111 if (day > kDaysInYear)
112 {
113 day -= kDaysInYear;
114 day -= 1;
115 do
116 {
117 years++;
118 day -= kDaysInYear;
119 } while (day >= 0);
120 day += kDaysInYear;
121 if (day >= kFeb29)
122 {
123 day++;
124 }
125 }
126
127 const auto year = kBaseYear + years;
128 const auto monthDay = getMonthDay(day);
129
130 auto result = Date(year, monthDay.first, monthDay.second);
131 result.dayOfYear = day;
132 return result;
133 }
134
135 uint32_t calcDays(Date date)
136 {

Callers 6

dateTickFunction · 0.85
drawFunction · 0.85
initialiseSnowLineFunction · 0.85
formatDateDMYFullFunction · 0.85
formatDateMYFullFunction · 0.85
formatDateMYAbbrevFunction · 0.85

Calls 2

getMonthDayFunction · 0.85
DateClass · 0.85

Tested by

no test coverage detected