Updated the monthNumTo3LetterAbbreviation function, it is no more needed to declare a buffer to store the 3 letters, instead a uint32_t is used

This commit is contained in:
anschrammh 2020-12-15 00:11:48 +01:00
parent 48991fe12e
commit 2b0698c7d0
2 changed files with 10 additions and 9 deletions

View File

@ -72,16 +72,17 @@ char *lastIndexOf(char *str, const char character)
* The monthNumTo3LetterAbbreviation function takes the month number from 1 to 12 and returns the abbreviation in a 3 letter
* format.
*/
char *monthNumTo3LetterAbbreviation(char *buffer, const uint8_t monthNumber)
uint32_t monthNumTo3LetterAbbreviation(const uint8_t monthNumber)
{
static const char monthArray[][4] = {{"Jan"},{"Feb"},{"Mar"},{"Apr"},{"May"},{"Jun"},{"Jul"},{"Aug"},{"Sep"},{"Oct"},{"Nov"},{"Dec"}};
if(buffer == NULL) return NULL;
/**
* This array contains months as 3 letter abbreviations
* Jan is written \0naJ and in hex : 0x006E614A an so on. They are thus 4Bytes aligned and easy to put and read back from prog mem :)
*/
static const uint32_t PROGMEM monthArray[] = {0x6E614A, 0x626546, 0x72614D, 0x727041, 0x79614D, 0x6E754A, 0x6C754A, 0x677541, 0x706553, 0x74634F, 0x766f4E, 0x636544};
uint32_t toReturn(0x6E614A); //Default to Jan.
if(monthNumber >= 1 && monthNumber <= 12)
strcpy_P(buffer, monthArray[monthNumber-1]);
else //If the month number is garbage, we return the first month of the year
strcpy_P(buffer, monthArray[0]);
toReturn = monthArray[monthNumber - 1];
return buffer;
return toReturn;
}

View File

@ -57,6 +57,6 @@ char *lastIndexOf(char *str, const char character);
char *dateTimeFormater(char *pointer, const uint8_t value, const char character);
char *monthNumTo3LetterAbbreviation(char *month, const uint8_t monthNumber);
uint32_t monthNumTo3LetterAbbreviation(const uint8_t monthNumber);
#endif //DEFINITION_H