Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
21 | jlesech | 1 | // Code by JeeLabs http://news.jeelabs.org/code/ |
2 | // Released to the public domain! Enjoy! |
||
3 | |||
4 | // Simple general-purpose date/time class (no TZ / DST / leap second handling!) |
||
5 | class DateTime { |
||
6 | public: |
||
7 | DateTime (uint32_t t =0); |
||
8 | DateTime (uint16_t year, uint8_t month, uint8_t day, |
||
9 | uint8_t hour =0, uint8_t min =0, uint8_t sec =0); |
||
10 | DateTime (const char* date, const char* time); |
||
11 | uint16_t year() const { return 2000 + yOff; } |
||
12 | uint8_t month() const { return m; } |
||
13 | uint8_t day() const { return d; } |
||
14 | uint8_t hour() const { return hh; } |
||
15 | uint8_t minute() const { return mm; } |
||
16 | uint8_t second() const { return ss; } |
||
17 | uint8_t dayOfWeek() const; |
||
18 | |||
19 | // 32-bit times as seconds since 1/1/2000 |
||
20 | long secondstime() const; |
||
21 | // 32-bit times as seconds since 1/1/1970 |
||
22 | uint32_t unixtime(void) const; |
||
23 | |||
24 | protected: |
||
25 | uint8_t yOff, m, d, hh, mm, ss; |
||
26 | }; |
||
27 | |||
28 | // RTC based on the DS1307 chip connected via I2C and the Wire library |
||
29 | class RTC_DS1307 { |
||
30 | public: |
||
31 | static uint8_t begin(void); |
||
32 | static void adjust(const DateTime& dt); |
||
33 | uint8_t isrunning(void); |
||
34 | static DateTime now(); |
||
35 | }; |
||
36 | |||
37 | // RTC using the internal millis() clock, has to be initialized before use |
||
38 | // NOTE: this clock won't be correct once the millis() timer rolls over (>49d?) |
||
39 | class RTC_Millis { |
||
40 | public: |
||
41 | static void begin(const DateTime& dt) { adjust(dt); } |
||
42 | static void adjust(const DateTime& dt); |
||
43 | static DateTime now(); |
||
44 | |||
45 | protected: |
||
46 | static long offset; |
||
47 | }; |