123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
-
- #ifndef _Time_h
- #ifdef __cplusplus
- #define _Time_h
- #include <inttypes.h>
- #ifndef __AVR__
- #include <sys/types.h> // for __time_t_defined, but avr libc lacks sys/types.h
- #endif
- #if !defined(__time_t_defined)
- typedef unsigned long time_t;
- #endif
- extern "C++" {
- typedef enum {timeNotSet, timeNeedsSync, timeSet
- } timeStatus_t ;
- typedef enum {
- dowInvalid, dowSunday, dowMonday, dowTuesday, dowWednesday, dowThursday, dowFriday, dowSaturday
- } timeDayOfWeek_t;
- typedef enum {
- tmSecond, tmMinute, tmHour, tmWday, tmDay,tmMonth, tmYear, tmNbrFields
- } tmByteFields;
- typedef struct {
- uint8_t Second;
- uint8_t Minute;
- uint8_t Hour;
- uint8_t Wday;
- uint8_t Day;
- uint8_t Month;
- uint8_t Year;
- } tmElements_t, TimeElements, *tmElementsPtr_t;
- #define tmYearToCalendar(Y) ((Y) + 1970)
- #define CalendarYrToTm(Y) ((Y) - 1970)
- #define tmYearToY2k(Y) ((Y) - 30)
- #define y2kYearToTm(Y) ((Y) + 30)
- typedef time_t(*getExternalTime)();
- #define SECS_PER_MIN ((time_t)(60UL))
- #define SECS_PER_HOUR ((time_t)(3600UL))
- #define SECS_PER_DAY ((time_t)(SECS_PER_HOUR * 24UL))
- #define DAYS_PER_WEEK ((time_t)(7UL))
- #define SECS_PER_WEEK ((time_t)(SECS_PER_DAY * DAYS_PER_WEEK))
- #define SECS_PER_YEAR ((time_t)(SECS_PER_DAY * 365UL))
- #define SECS_YR_2000 ((time_t)(946684800UL))
-
- #define numberOfSeconds(_time_) ((_time_) % SECS_PER_MIN)
- #define numberOfMinutes(_time_) (((_time_) / SECS_PER_MIN) % SECS_PER_MIN)
- #define numberOfHours(_time_) (((_time_) % SECS_PER_DAY) / SECS_PER_HOUR)
- #define dayOfWeek(_time_) ((((_time_) / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1)
- #define elapsedDays(_time_) ((_time_) / SECS_PER_DAY)
- #define elapsedSecsToday(_time_) ((_time_) % SECS_PER_DAY)
- #define previousMidnight(_time_) (((_time_) / SECS_PER_DAY) * SECS_PER_DAY)
- #define nextMidnight(_time_) (previousMidnight(_time_) + SECS_PER_DAY)
- #define elapsedSecsThisWeek(_time_) (elapsedSecsToday(_time_) + ((dayOfWeek(_time_)-1) * SECS_PER_DAY))
- #define previousSunday(_time_) ((_time_) - elapsedSecsThisWeek(_time_))
- #define nextSunday(_time_) (previousSunday(_time_)+SECS_PER_WEEK)
- #define minutesToTime_t ((M)) ( (M) * SECS_PER_MIN)
- #define hoursToTime_t ((H)) ( (H) * SECS_PER_HOUR)
- #define daysToTime_t ((D)) ( (D) * SECS_PER_DAY)
- #define weeksToTime_t ((W)) ( (W) * SECS_PER_WEEK)
- int hour();
- int hour(time_t t);
- int hourFormat12();
- int hourFormat12(time_t t);
- uint8_t isAM();
- uint8_t isAM(time_t t);
- uint8_t isPM();
- uint8_t isPM(time_t t);
- int minute();
- int minute(time_t t);
- int second();
- int second(time_t t);
- int day();
- int day(time_t t);
- int weekday();
- int weekday(time_t t);
- int month();
- int month(time_t t);
- int year();
- int year(time_t t);
- time_t now();
- void setTime(time_t t);
- void setTime(int hr,int min,int sec,int day, int month, int yr);
- void adjustTime(long adjustment);
-
- #define dt_MAX_STRING_LEN 9
- char* monthStr(uint8_t month);
- char* dayStr(uint8_t day);
- char* monthShortStr(uint8_t month);
- char* dayShortStr(uint8_t day);
-
- timeStatus_t timeStatus();
- void setSyncProvider( getExternalTime getTimeFunction);
- void setSyncInterval(time_t interval);
- void breakTime(time_t time, tmElements_t &tm);
- time_t makeTime(const tmElements_t &tm);
- }
- #endif
- #endif
|