AceTime  0.1
Date and time classes for Arduino that supports the TZ DAtabase, and a system clock synchronized from an NTP server or an RTC chip.
DateStrings.h
1 #ifndef ACE_TIME_COMMON_DATE_STRINGS_H
2 #define ACE_TIME_COMMON_DATE_STRINGS_H
3 
4 #include <stdint.h>
5 #include <string.h>
6 #include "flash.h"
7 
8 namespace ace_time {
9 namespace common {
10 
22 class DateStrings {
23  public:
27  static const uint8_t kBufferSize = 10;
28 
30  static const uint8_t kShortNameLength = 3;
31 
33  const char* monthLongString(uint8_t month) const {
34  uint8_t index = (month < kNumMonthNames) ? month : 0;
35  strcpy_P(mBuffer, kMonthNames[index]);
36  return mBuffer;
37  }
38 
40  const char* monthShortString(uint8_t month) const {
41  uint8_t index = (month < kNumMonthNames) ? month : 0;
42  strncpy_P(mBuffer, kMonthNames[index], kShortNameLength);
43  mBuffer[kShortNameLength] = '\0';
44  return mBuffer;
45  }
46 
48  const char* weekDayLongString(uint8_t weekDay) const {
49  uint8_t index = (weekDay < kNumWeekDayNames) ? weekDay : 0;
50  strcpy_P(mBuffer, kWeekDayNames[index]);
51  return mBuffer;
52  }
53 
55  const char* weekDayShortString(uint8_t weekDay) const {
56  uint8_t index = (weekDay < kNumWeekDayNames) ? weekDay : 0;
57  strncpy_P(mBuffer, kWeekDayNames[index], kShortNameLength);
58  mBuffer[kShortNameLength] = '\0';
59  return mBuffer;
60  }
61 
62  private:
63  static const char * const kWeekDayNames[];
64  static const char * const kMonthNames[];
65  static const uint8_t kNumWeekDayNames;
66  static const uint8_t kNumMonthNames;
67 
68  mutable char mBuffer[kBufferSize];
69 };
70 
71 }
72 }
73 
74 #endif
Class that translates a numeric month (1-12) or weekDay (1-7) into a human readable string...
Definition: DateStrings.h:22
const char * monthShortString(uint8_t month) const
Return the short month name.
Definition: DateStrings.h:40
static const uint8_t kShortNameLength
Number of prefix characters to use to create a short name.
Definition: DateStrings.h:30
const char * weekDayShortString(uint8_t weekDay) const
Return the short weekDay name.
Definition: DateStrings.h:55
const char * weekDayLongString(uint8_t weekDay) const
Return the short weekDay name.
Definition: DateStrings.h:48
static const uint8_t kBufferSize
Length of the longest month or week name, including the &#39;\0&#39; terminator.
Definition: DateStrings.h:27
const char * monthLongString(uint8_t month) const
Return the long month name.
Definition: DateStrings.h:33