Skip to content

Commit

Permalink
Merge pull request #4 from hasenradball/rename_show_DateTime
Browse files Browse the repository at this point in the history
rename function show_DateTime() => strf_DateTime()
  • Loading branch information
hasenradball authored Oct 29, 2023
2 parents 50121ad + 910a493 commit c2588f0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This library was based on the master branch of [NorthernWidget/DS3231](https://g
* using standardized functions of the `time.h` library.
* introduce a `struct tm` which holds all relevant date and time values.
* restrucure comments, so that syntax highlighting works fine.
* add a `show_DateTime()` function with can be used to print a user specific(self defined) DateTime string easily.
* add a `strf_DateTime()` function with can be used to print a user specific(self defined) DateTime string easily.

## Contents

Expand Down Expand Up @@ -275,7 +275,7 @@ further lists the DateTime class methods (for Documentation look into the src fi
- getWeekDay()
- getYearDay()
- getDST()
- show_DateTime()
- strf_DateTime()
- getUnixTime()
- getY2KTime()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ void setup () {
Serial.print("\n\nPrint Data via function <showTimeFormated> of Struct tm:\n\t");
showTimeFormated(tstmp);

Serial.print("\nPrint Data via DataTime function <show_DateTime>:\n\t");
Serial.print("\nPrint Data via DataTime function <strf_DateTime>:\n\t");
char buffer[80];
datetime.show_DateTime(buffer, sizeof(buffer));
datetime.strf_DateTime(buffer, sizeof(buffer));
Serial.println(buffer);

//Serial.print("\nPrint __DATE__ and __TIME__:\n");
Expand Down
4 changes: 2 additions & 2 deletions examples/setEpoch/setEpoch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ void setup () {
showTimeFormated(tstmp);

// Use smart print function from DateTime class
Serial.print("\nUse show_DateTime function:\n ");
Serial.print("\nUse strf_DateTime function:\n ");
// provide a buffer
char buffer[80];
datetime.show_DateTime(buffer, sizeof(buffer));
datetime.strf_DateTime(buffer, sizeof(buffer));
Serial.println(buffer);
}

Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DateTime KEYWORD1
now KEYWORD2
getY2kTime KEYWORD2
getUnixTime KEYWORD2
strf_DateTime KEYWORD2
getWeekDay KEYWORD2
getDST KEYWORD2
getSecond KEYWORD2
Expand Down
8 changes: 5 additions & 3 deletions src/DS3231-RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,17 @@ void DateTime::set_timstamps() {
}

/**
* @brief smart time print function based on the standard strftime function
* see: https://en.cppreference.com/w/cpp/chrono/c/strftime
* @brief function to format a DateTime string in an buffer based on the standard strftime function
*
* see: https://cplusplus.com/reference/ctime/strftime/
* or: https://en.cppreference.com/w/cpp/chrono/c/strftime
*
* @param buffer buffer for time string
* @param buffersize size of buffer
* @param formatSpec define format see strftime
* @return size_t lenth of used buffer
*/
size_t DateTime::show_DateTime(char *buffer, size_t buffersize, const char *formatSpec) {
size_t DateTime::strf_DateTime(char *buffer, size_t buffersize, const char *formatSpec) {
size_t len {strftime(buffer, buffersize, formatSpec, &_tm)};
return len;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DS3231-RTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DateTime {
int8_t getWeekDay() const { return _tm.tm_wday; }
int16_t getYearDay() const { return _tm.tm_yday; }
int16_t getDST() const { return _tm.tm_isdst; }
size_t show_DateTime(char *buffer, size_t buffersize, const char *formatSpec = "%a %h %d %T %Y");
size_t strf_DateTime(char *buffer, size_t buffersize, const char *formatSpec = "%a %h %d %T %Y");

// time_t value as seconds since 1/1/2000
time_t getY2kTime() const { return _y2k_timestamp; }
Expand Down

0 comments on commit c2588f0

Please sign in to comment.