Help with P5 RGB64x32 Matrix Clock with ESP32

Difficulty adding (Day of the Week, Day of the Month, and Day of the Year) to the code itself (post #88) that "david_2018" modified from the original code. If there isn't a kind soul here who can do this for me (of course, with great kindness), I'll just leave it as is and forget all about it.
It's not laziness, it's difficulty understanding how a more complex Arduino code works.

Hello everyone.

After causing so much trouble for many of you, I'd like to know why this Matrix doesn't work with this code? Logically, shouldn't it work?

My Matrix has these specifications:
-P5-320X160-16S (64*32 pixels)
-1/16 Scan Current
-HUB75

Thank you all, especially @david_2018, who got part of the code working.

Isn't the panel working?
You previously wrote (in your message #96) that the matrix works and shows the time in the upper half. Or is this a different matrix?
What is your question actually about?

@b707

So, if you read message #96, you'll understand that the complete code includes a few more things, such as Date (Day/Month/Year) and Day of the Week, as in this video: https://www.youtube.com/watch?v=Pu28vPFUX0w. However, in the original code, my Display was exhibiting, let's say, a flaw, which is turning the screen on and off in a repeated loop. So, @david_2018 made a correction to the code, showing the Time but omitting the rest.

If the panel shows the time, doesn't that mean it's working and therefore, that answers the question?

The reason there is no date on the panel is not in the matrix, but in your code.

I added the following, as @david_2018 did in the code in post #88, but the dates, such as the day of the week, month, and year, are wrong; today, for example, shows 12/31/1969.

void initializeDisplay() {
  matrix.fillScreen(0);
  matrix.setFont(&FreeSansBold9pt7b);
  matrix.setCursor(0, 13);
  last_t = time(NULL);
  struct tm* tm = localtime(&last_t);
  matrix.setTextColor(matrix.color444(15, 15, 15));
  matrix.printf("%02d:%02d", tm->tm_hour, tm->tm_min);
  
  matrix.setFont();
  matrix.printf(":%02d", tm->tm_sec);

  matrix.setCursor(14, 16);
  matrix.setTextColor(matrix.color444(100, 50, 0));
  matrix.printf("%s", wd[tm->tm_wday]);

  matrix.setCursor(2, 24);
  matrix.setTextColor(matrix.color444(12, 12, 4));
  matrix.printf("%02d/%02d/%04d\n", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900);
}

I deduced that if this part of the code handles the time, adding the rest, as in the continuation, would handle the seconds, day of the week, day of the month, month, and year, but I know something is missing, which I'm not aware of.

Confirming: Today it is showing Tuesday, December 31, 1969. The time is correct. This is the current code:

#include <WiFi.h>
#include <Adafruit_GFX.h>
#include <P3RGB64x32MatrixPanel.h>
#include <Fonts/FreeSansBold9pt7b.h>

// constructor with default pin wiring
P3RGB64x32MatrixPanel matrix;

char ssid[] = "Xxxxxxx";
char pass[] = "Xxxxxxxxxxxx";

#define TZ (-3*3600) /*JST*/

time_t last_t;
const char* const wd[7] = {"Domingo", "Segunda", "Terca", "Quarta", "Quinta", "Sexta", "Sabado"};

void setup() {
  Serial.begin(115200);
  Serial.print("Attempting to connect to Network named: ");
  Serial.println(ssid);                   // print the network name (SSID);

  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println("");
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  configTime(TZ, 0, "ntp.nict.jp", "ntp.jst.mfeed.ad.jp"); // enable NTP

  matrix.begin();                           // Configura a matriz de LEDs

  initializeDisplay();
}

void initializeDisplay() {
  matrix.fillScreen(0);
  matrix.setFont(&FreeSansBold9pt7b);
  matrix.setCursor(0, 13);
  last_t = time(NULL);
  struct tm* tm = localtime(&last_t);
  matrix.setTextColor(matrix.color444(15, 15, 15));
  matrix.printf("%02d:%02d", tm->tm_hour, tm->tm_min); // Imprime hora e minuto
  
  matrix.setFont();
  matrix.printf(":%02d", tm->tm_sec); // Imprime os segundos

  matrix.setCursor(14, 16);
  matrix.setTextColor(matrix.color444(100, 50, 0));
  matrix.printf("%s", wd[tm->tm_wday]); // Imprime dia da semana

  matrix.setCursor(2, 24);
  matrix.setTextColor(matrix.color444(12, 12, 4));
  matrix.printf("%02d/%02d/%04d\n", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); // Imprime dia do mês, mês, e dia do ano

  matrix.swapBuffer(); // exibe a imagem escrita no buffer
  delay(500);
}

void loop() {
  time_t t;
  struct tm *tm;

  t = time(NULL);
  if (last_t == t) return;

  char current[11];
  char previous[11];
  tm = localtime(&last_t);
  struct tm tmPrev = *tm;
  //struct tm tmPrev = *localtime(&last_t);
  tm = localtime(&t);
  if ((tmPrev.tm_hour != tm->tm_hour) || (tmPrev.tm_min != tm->tm_min)) {
    sprintf(previous, "%02d:%02d", tmPrev.tm_hour, tmPrev.tm_min);
    sprintf(current, "%02d:%02d", tm->tm_hour, tm->tm_min);
    matrix.setFont(&FreeSansBold9pt7b);
    matrix.setCursor(0, 13);
    updateText(previous, current, matrix.color444(15, 15, 15), 0);
  }

  matrix.setFont();
  matrix.setCursor(50, 7);
  sprintf(previous, "%02d", tmPrev.tm_sec);
  sprintf(current, "%02d", tm->tm_sec);
  updateText(previous, current, matrix.color444(15, 15, 15), 0);

  last_t = t;

  //check WiFi connection status
  const unsigned long statusCheckInterval = 30000; //30 seconds
  static unsigned long previousMillis = millis() - statusCheckInterval;
  if ((WiFi.status() != WL_CONNECTED) && ((millis() - previousMillis) >= statusCheckInterval)) {
    Serial.println("WiFi connection lost, reconnecting...");
    WiFi.disconnect();
    WiFi.reconnect();
    previousMillis = millis();
  }
}

void updateText(const char* oldText, const char* newText, const uint16_t colorForeground, const uint16_t colorBackground) {
  if (strlen(newText) != strlen(oldText)) {
    return;
  }
  matrix.setTextColor(colorForeground);
  while (*newText) {
    if (*oldText != *newText) {
      int cursorPosX = matrix.getCursorX();
      int cursorPosY = matrix.getCursorY();
      matrix.setTextColor(colorBackground);
      matrix.print(*oldText);
      matrix.setTextColor(colorForeground);
      matrix.setCursor(cursorPosX, cursorPosY);
    }
    matrix.print(*newText);
    oldText++;
    newText++;
  }
}