AceTime  0.5.2
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 "compat.h"
12 
13 namespace ace_time {
14 namespace common {
15 
27 class DateStrings {
28  public:
32  static const uint8_t kBufferSize = 10;
33 
38  static const uint8_t kShortNameLength = 3;
39 
41  const char* monthLongString(uint8_t month) {
42  uint8_t index = (month < kNumMonthNames) ? month : 0;
43  strncpy_P(mBuffer, getStringAt(kMonthNames, index), kBufferSize);
44  mBuffer[kBufferSize - 1] = '\0';
45  return mBuffer;
46  }
47 
49  const char* monthShortString(uint8_t month) {
50  uint8_t index = (month < kNumMonthNames) ? month : 0;
51  strncpy_P(mBuffer, getStringAt(kMonthNames, index), kShortNameLength);
52  mBuffer[kShortNameLength] = '\0';
53  return mBuffer;
54  }
55 
57  const char* dayOfWeekLongString(uint8_t dayOfWeek) {
58  uint8_t index = (dayOfWeek < kNumDayOfWeekNames) ? dayOfWeek : 0;
59  strncpy_P(mBuffer, getStringAt(kDayOfWeekNames, index), kBufferSize);
60  mBuffer[kBufferSize - 1] = '\0';
61  return mBuffer;
62  }
63 
65  const char* dayOfWeekShortString(uint8_t dayOfWeek) {
66  uint8_t index = (dayOfWeek < kNumDayOfWeekNames) ? dayOfWeek : 0;
67  strncpy_P(mBuffer, getStringAt(kDayOfWeekNames, index), kShortNameLength);
68  mBuffer[kShortNameLength] = '\0';
69  return mBuffer;
70  }
71 
72  private:
73  static const char* getStringAt(const char* const* strings, uint8_t i) {
74  return (const char*) pgm_read_ptr(&strings[i]);
75  }
76 
77  static const char * const kDayOfWeekNames[];
78  static const char * const kMonthNames[];
79  static const uint8_t kNumDayOfWeekNames;
80  static const uint8_t kNumMonthNames;
81 
82  char mBuffer[kBufferSize];
83 };
84 
85 }
86 }
87 
88 #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:38
const char * monthLongString(uint8_t month)
Return the long month name.
Definition: DateStrings.h:41
Macros and definitions that provide a consistency layer among the various Arduino boards for compatib...
const char * monthShortString(uint8_t month)
Return the short month name.
Definition: DateStrings.h:49
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:57
const char * dayOfWeekShortString(uint8_t dayOfWeek)
Return the short dayOfWeek name.
Definition: DateStrings.h:65