AceTime  0.5
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
DateStrings.h
1 /*
2  * MIT License
3  * Copyright (c) 2018 Brian T. Park
4  */
5 
6 #ifndef ACE_TIME_COMMON_DATE_STRINGS_H
7 #define ACE_TIME_COMMON_DATE_STRINGS_H
8 
9 #include <stdint.h>
10 #include <string.h>
11 #include "flash.h"
12 
13 namespace ace_time {
14 namespace common {
15 
27 class DateStrings {
28  public:
32  static const uint8_t kBufferSize = 10;
33 
35  static const uint8_t kShortNameLength = 3;
36 
38  const char* monthLongString(uint8_t month) {
39  uint8_t index = (month < kNumMonthNames) ? month : 0;
40  strcpy_P(mBuffer, kMonthNames[index]);
41  return mBuffer;
42  }
43 
45  const char* monthShortString(uint8_t month) {
46  uint8_t index = (month < kNumMonthNames) ? month : 0;
47  strncpy_P(mBuffer, kMonthNames[index], kShortNameLength);
48  mBuffer[kShortNameLength] = '\0';
49  return mBuffer;
50  }
51 
53  const char* dayOfWeekLongString(uint8_t dayOfWeek) {
54  uint8_t index = (dayOfWeek < kNumDayOfWeekNames) ? dayOfWeek : 0;
55  strcpy_P(mBuffer, kDayOfWeekNames[index]);
56  return mBuffer;
57  }
58 
60  const char* dayOfWeekShortString(uint8_t dayOfWeek) {
61  uint8_t index = (dayOfWeek < kNumDayOfWeekNames) ? dayOfWeek : 0;
62  strncpy_P(mBuffer, kDayOfWeekNames[index], kShortNameLength);
63  mBuffer[kShortNameLength] = '\0';
64  return mBuffer;
65  }
66 
67  private:
68  static const char * const kDayOfWeekNames[];
69  static const char * const kMonthNames[];
70  static const uint8_t kNumDayOfWeekNames;
71  static const uint8_t kNumMonthNames;
72 
73  char mBuffer[kBufferSize];
74 };
75 
76 }
77 }
78 
79 #endif
Class that translates a numeric month (1-12) or dayOfWeek (1-7) into a human readable string...
Definition: DateStrings.h:27
static const uint8_t kShortNameLength
Number of prefix characters to use to create a short name.
Definition: DateStrings.h:35
const char * monthLongString(uint8_t month)
Return the long month name.
Definition: DateStrings.h:38
const char * monthShortString(uint8_t month)
Return the short month name.
Definition: DateStrings.h:45
static const uint8_t kBufferSize
Length of the longest month or week name, including the &#39;\0&#39; terminator.
Definition: DateStrings.h:32
const char * dayOfWeekLongString(uint8_t dayOfWeek)
Return the short dayOfWeek name.
Definition: DateStrings.h:53
const char * dayOfWeekShortString(uint8_t dayOfWeek)
Return the short dayOfWeek name.
Definition: DateStrings.h:60