-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateStrings.cpp
More file actions
124 lines (106 loc) · 4.53 KB
/
Copy pathDateStrings.cpp
File metadata and controls
124 lines (106 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* DateStrings.cpp
* Definitions for date strings for use with the Time library
*
* Updated for Arduino 1.5.7 18 July 2014
*
* No memory is consumed in the sketch if your code does not call any of the string methods
* You can change the text of the strings, make sure the short strings are each exactly 3 characters
* the long strings can be any length up to the constant dt_MAX_STRING_LEN defined in TimeLib.h
*
*/
#include <Arduino.h>
// Arduino.h should properly define PROGMEM, PGM_P, strcpy_P, pgm_read_byte, pgm_read_ptr
// But not all platforms define these as they should. If you find a platform needing these
// defined, or if any this becomes unnecessary as platforms improve, please send a pull req.
//#if defined(ESP8266)
//#undef PROGMEM
//#define PROGMEM
//#endif
#include <pgmspace.h>
#include "sntpTime.h"
// the short strings for each day or month must be exactly dt_SHORT_STR_LEN
#define kShortNameLength 3 // the length of short strings
#define kBufferSize 10
#define kNumMonthNames 13
#define kNumDayOfWeekNames 8
// static char mBuffer[kBufferSize]; // must be big enough for longest string and the terminating null
static const char kError[] PROGMEM = "Error";
static const char kJanuary[] PROGMEM = "January";
static const char kFebruary[] PROGMEM = "February";
static const char kMarch[] PROGMEM = "March";
static const char kApril[] PROGMEM = "April";
static const char kMay[] PROGMEM = "May";
static const char kJune[] PROGMEM = "June";
static const char kJuly[] PROGMEM = "July";
static const char kAugust[] PROGMEM = "August";
static const char kSeptember[] PROGMEM = "September";
static const char kOctober[] PROGMEM = "October";
static const char kNovember[] PROGMEM = "November";
static const char kDecember[] PROGMEM = "December";
// Place pointers into PROGMEM as well, saving 26 bytes of RAM.
// Use getStringAt() to access.
const char* const MonthLongNames_P[] PROGMEM = {
kError, kJanuary, kFebruary, kMarch, kApril, kMay, kJune,
kJuly, kAugust, kSeptember, kOctober, kNovember, kDecember
};
static const char kErr[] PROGMEM = "Err";
static const char kJan[] PROGMEM = "Jan";
static const char kFeb[] PROGMEM = "Feb";
static const char kMar[] PROGMEM = "Mar";
static const char kApr[] PROGMEM = "Apr";
static const char kJun[] PROGMEM = "Jun";
static const char kJul[] PROGMEM = "Jul";
static const char kAug[] PROGMEM = "Aug";
static const char kSep[] PROGMEM = "Sep";
static const char kOct[] PROGMEM = "Oct";
static const char kNov[] PROGMEM = "Nov";
static const char kDec[] PROGMEM = "Dec";
// Place pointers into PROGMEM as well, saving 26 bytes of RAM.
const char* const MonthShortNames_P[] PROGMEM = {
kErr, kJan, kFeb, kMar, kApr, kMay, kJun,
kJul, kAug, kSep, kOct, kNov, kDec
};
static const char kMonday[] PROGMEM = "Monday";
static const char kTuesday[] PROGMEM = "Tuesday";
static const char kWednesday[] PROGMEM = "Wednesday";
static const char kThursday[] PROGMEM = "Thursday";
static const char kFriday[] PROGMEM = "Friday";
static const char kSaturday[] PROGMEM = "Saturday";
static const char kSunday[] PROGMEM = "Sunday";
// Place pointers into PROGMEM as well, saving 16 bytes of RAM.
// ISO8601 says Monday=1, Sunday=7.
const char* const dayNames_P[] PROGMEM = {
kError, kMonday, kTuesday, kWednesday, kThursday, kFriday, kSaturday, kSunday
};
static const char kMon[] PROGMEM = "Mon";
static const char kTue[] PROGMEM = "Tue";
static const char kWed[] PROGMEM = "Wed";
static const char kThu[] PROGMEM = "Thu";
static const char kFri[] PROGMEM = "Fri";
static const char kSat[] PROGMEM = "Sat";
static const char kSun[] PROGMEM = "Sun";
// Place pointers into PROGMEM as well, saving 16 bytes of RAM.
// ISO8601 says Monday=1, Sunday=7.
const char* const dayShortNames_P[] PROGMEM = {
kErr, kMon, kTue, kWed, kThu, kFri, kSat, kSun
};
/** Return the long month name. 0=Error, 1=January, 12=December. */
const char* monthStr(uint8_t month) {
uint8_t index = (month < kNumMonthNames) ? month : 0;
return MonthLongNames_P[index];
}
/** Return the short month name. 0=Err, 1=Jan, 12=Dec. */
const char* monthShortStr(uint8_t month) {
uint8_t index = (month < kNumMonthNames) ? month : 0;
return MonthShortNames_P[index];
}
/** Return the short dayOfWeek name. 0=Error, 1=Monday, 7=Sunday. */
const char * dayStr(uint8_t day) {
uint8_t index = (day < kNumDayOfWeekNames) ? day : 0;
return dayNames_P[index];
}
/** Return the short dayOfWeek name. 0=Err, 1=Mon, 7=Sun. */
const char* dayShortStr(uint8_t day) {
uint8_t index = (day < kNumDayOfWeekNames) ? day : 0;
return dayShortNames_P[index];
}