DS3231 not counting up after moving parts of code to a class

So I have this general utility class, part of which includes some functions that revolve around a DS3231 RTC using Rtclib. I found myself doing:

DateTime now = rtc.now();
char[] buf = "MM-DD-YYYY";
String t = now.toString(buf);

a lot and wanted to simplify my life by adding the function the utility class. I didn’t put it in the main .ino file just because the class can be used for other implementations on the same hardware.

Unfortunately a simple test like:

#include <Esper.h>

Esper sys(0x4D, 14, 15);

void setup() {
  // put your setup code here, to run once:
  if (!sys.initRtc()) {
    Serial.println(F("Failed to initialize RTC!"));

void loop() {
  // put your main code here, to run repeatedly:

Results in:

01/05/20 03:15:45
01/05/20 03:15:45
01/05/20 03:15:45

For some reason the time isn’t ticking up when using the utility class I created.

Using the default RTClib example everything works fine, as well as previous implementations where I had the first code block in the .ino so it isn’t a hardware issue.

I’ve attached my utility class below.

I have a feeling that it is something to do with instances but I’m not that great with C.

Note: on restarting the device the time updates to the correct time but then continues outputting that same time as before.

Esper.cpp (7.99 KB)

Esper.h (1.75 KB)

Ok so I found that by changing:

String rtcTimeString(char buf[] = "MM/DD/YY hh:mm:ss");


String rtcTimeString();

and consequently:

String Esper::rtcTimeString() {
  DateTime now = rtc.now();
  char buf2[] = "MM/DD/YY hh:mm:ss";
  return now.toString(buf2);

It works.

Is there a way I can still have this default "MM/DD/YY hh:mm:ss" without effecting functionality and allowing to pass other params to the function like "MM-DD-YYYY"?