sys/timex: fix incompatible atmega time.h

This commit is contained in:
Matthew Blue 2018-05-19 11:30:46 -04:00
parent 442634728f
commit dfa8fb919d
4 changed files with 20 additions and 0 deletions

View File

@ -153,6 +153,12 @@ extern "C" {
int16_t tm_isdst; /**< Daylight Saving Time flag */ int16_t tm_isdst; /**< Daylight Saving Time flag */
}; };
/**
ATmega compatibility problem define
NOTE: Added for RIOT compatibility
*/
#define ATMEGA_INCOMPATIBLE_TIME_H
#ifndef __DOXYGEN__ #ifndef __DOXYGEN__
/* We have to provide clock_t / CLOCKS_PER_SEC so that libstdc++-v3 can /* We have to provide clock_t / CLOCKS_PER_SEC so that libstdc++-v3 can
be built. We define CLOCKS_PER_SEC via a symbol _CLOCKS_PER_SEC_ be built. We define CLOCKS_PER_SEC via a symbol _CLOCKS_PER_SEC_

View File

@ -84,7 +84,11 @@ int tm_doomsday(int year) CONST;
* @param[out] wday Returns the day of the week. * @param[out] wday Returns the day of the week.
* @param[out] yday Returns the day of the year (Jan 1st is 0). * @param[out] yday Returns the day of the year (Jan 1st is 0).
*/ */
#ifndef ATMEGA_INCOMPATIBLE_TIME_H
void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday); void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday);
#else
void tm_get_wyday(int year, int mon, int mday, int8_t *wday, int16_t *yday);
#endif
/** /**
* @brief Fills in `struct tm::tm_wday` and `struct tm::tm_yday` given a date. * @brief Fills in `struct tm::tm_wday` and `struct tm::tm_yday` given a date.

View File

@ -49,7 +49,11 @@ int tm_doomsday(int year)
return result; return result;
} }
#ifndef ATMEGA_INCOMPATIBLE_TIME_H
void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday) void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday)
#else
void tm_get_wyday(int year, int mon, int mday, int8_t *wday, int16_t *yday)
#endif
{ {
int is_leap_year = tm_is_leap_year(year); int is_leap_year = tm_is_leap_year(year);
*yday = TM_MON_DAYS_ACCU[mon] + mday + (mon <= TM_MON_FEB ? 0 : is_leap_year) - 1; *yday = TM_MON_DAYS_ACCU[mon] + mday + (mon <= TM_MON_FEB ? 0 : is_leap_year) - 1;

View File

@ -113,7 +113,13 @@ static int cmd_day(int argc, char **argv)
puts("The supplied date is invalid, but no error should occur."); puts("The supplied date is invalid, but no error should occur.");
} }
#ifndef ATMEGA_INCOMPATIBLE_TIME_H
int wday, yday; int wday, yday;
#else
int8_t wday;
int16_t yday;
#endif
tm_get_wyday(year, mon - 1, day, &wday, &yday); tm_get_wyday(year, mon - 1, day, &wday, &yday);
printf("What weekday was %04d-%02d-%02d? The %d(th) day of the year was a %.3s.\n", printf("What weekday was %04d-%02d-%02d? The %d(th) day of the year was a %.3s.\n",
year, mon, day, yday + 1, DAY_NAMES[wday]); year, mon, day, yday + 1, DAY_NAMES[wday]);