MCPcopy Create free account
hub / github.com/comaps/comaps / GetDayTime

Function GetDayTime

libs/base/sunrise_sunset.cpp:207–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205} // namespace
206
207DayTimeType GetDayTime(time_t timeUtc, double latitude, double longitude)
208{
209 auto const sunrise = CalculateDayEventTime(timeUtc, latitude, longitude, true /* sunrise */);
210 auto const sunset = CalculateDayEventTime(timeUtc, latitude, longitude, false /* sunrise */);
211
212 // Edge cases: polar day and polar night
213 if (sunrise.first == DayEventType::PolarDay || sunset.first == DayEventType::PolarDay)
214 return DayTimeType::PolarDay;
215 if (sunrise.first == DayEventType::PolarNight || sunset.first == DayEventType::PolarNight)
216 return DayTimeType::PolarNight;
217
218 if (timeUtc < sunrise.second)
219 {
220 auto const prevSunrise = CalculateDayEventTime(timeUtc - kOneDaySeconds, latitude, longitude, true /* sunrise */);
221 auto const prevSunset = CalculateDayEventTime(timeUtc - kOneDaySeconds, latitude, longitude, false /* sunrise */);
222
223 if (timeUtc >= prevSunset.second)
224 return DayTimeType::Night;
225 if (timeUtc < prevSunrise.second)
226 return DayTimeType::Night;
227 return DayTimeType::Day;
228 }
229 if (timeUtc > sunset.second)
230 {
231 auto const nextSunrise = CalculateDayEventTime(timeUtc + kOneDaySeconds, latitude, longitude, true /* sunrise */);
232 auto const nextSunset = CalculateDayEventTime(timeUtc + kOneDaySeconds, latitude, longitude, false /* sunrise */);
233
234 if (timeUtc < nextSunrise.second)
235 return DayTimeType::Night;
236 if (timeUtc > nextSunset.second)
237 return DayTimeType::Night;
238 return DayTimeType::Day;
239 }
240
241 return DayTimeType::Day;
242}
243
244std::string DebugPrint(DayTimeType type)
245{

Callers 3

MoveTypeMethod · 0.85
UNIT_TESTFunction · 0.85

Calls 1

CalculateDayEventTimeFunction · 0.85

Tested by 1

UNIT_TESTFunction · 0.68