Skip to content

Commit 9490bf3

Browse files
committed
TimeLib defines DAYS_PER_WEEK as type time_t with a value of 7. TimeLib's time_t is defined as unsigned long with a value of 7. This is compatable with NeoGPS declaration of DAYS_PER_WEEK with type uint8_t if cast to uint8_t. I modified the code to check if DAYS_PER_WEEK is defined and cast DAYS_PER_WEEK as uint8_t when used.
This is an alternate way to resolve the conflict between NeoGPS and TimeLib. User, tscofield, proposed a similar fix by renaming DAYS_PER_WEEK but I believe this may be a slightly better resolution to the issue. See issues - [https://github.com/SlashDevin/NeoGPS/pull/115](https://github.com/SlashDevin/NeoGPS/pull/115 "NeoGPS Issue 115") - [https://github.com/PaulStoffregen/Time/issues/163](https://github.com/PaulStoffregen/Time/issues/163 "TimeLib Issue 163") BTW: I looked into applying a similar fix to TimeLib but the issue only seemed to be resolved when applied to NeoGPS.
1 parent 1707c2c commit 9490bf3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/NeoTime.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ const uint8_t MINUTES_PER_HOUR = 60;
4141
const uint16_t SECONDS_PER_HOUR = (uint16_t) SECONDS_PER_MINUTE * MINUTES_PER_HOUR;
4242
const uint8_t HOURS_PER_DAY = 24;
4343
const uint32_t SECONDS_PER_DAY = (uint32_t) SECONDS_PER_HOUR * HOURS_PER_DAY;
44-
const uint8_t DAYS_PER_WEEK = 7;
44+
#ifndef DAYS_PER_WEEK
45+
const uint8_t DAYS_PER_WEEK = 7;
46+
#endif
4547

4648
/**
4749
* Common date/time structure
@@ -192,7 +194,7 @@ struct time_t {
192194
*/
193195
static uint8_t weekday_for(uint16_t dayno)
194196
{
195-
return ((dayno+epoch_weekday()-1) % DAYS_PER_WEEK) + 1;
197+
return ((dayno+epoch_weekday()-1) % (uint8_t)DAYS_PER_WEEK) + 1;
196198
}
197199

198200
/**

0 commit comments

Comments
 (0)