Error tmElements_t_ tm; does not name a type

/*
SetTime.ino sketch to set the time of DS1307 RTC - created by Paul Stoffregen
github.com/PaulStoffregen/DS1307RTC/blob/master/examples/SetTime/SetTime.ino
 */
 
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>

const char *monthName[12] = {
  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};

tmElements_t tm;

void setup() {
  bool parse=false;
  bool config=false;

  // get the date and time the compiler was run
  if (getDate(__DATE__) && getTime(__TIME__)) {
    parse = true;
    // and configure the RTC with this info
    if (RTC.write(tm)) {
      config = true;
    }
  }

  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor
  delay(200);
  if (parse && config) {
    Serial.print("DS1307 configured Time=");
    Serial.print(__TIME__);
    Serial.print(", Date=");
    Serial.println(__DATE__);
  } else if (parse) {
    Serial.println("DS1307 Communication Error :-{");
    Serial.println("Please check your circuitry");
  } else {
    Serial.print("Could not parse info from the compiler, Time=\"");
    Serial.print(__TIME__);
    Serial.print("\", Date=\"");
    Serial.print(__DATE__);
    Serial.println("\"");
  }
}

void loop() {
}

bool getTime(const char *str)
{
  int Hour, Min, Sec;

  if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
  tm.Hour = Hour;
  tm.Minute = Min;
  tm.Second = Sec;
  return true;
}

bool getDate(const char *str)
{
  char Month[12];
  int Day, Year;
  uint8_t monthIndex;

  if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
  for (monthIndex = 0; monthIndex < 12; monthIndex++) {
    if (strcmp(Month, monthName[monthIndex]) == 0) break;
  }
  if (monthIndex >= 12) return false;
  tm.Day = Day;
  tm.Month = monthIndex + 1;
  tm.Year = CalendarYrToTm(Year);
  return true;
}

// Not sure how to post error codes, so here goes
/*
Arduino: 1.8.19 (Windows 10), Board: "Arduino MKR WiFi 1010"

In file included from C:\Arduino_Projects\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO.ino:8:0:

C:\Users\brin8\Documents\Arduino\libraries\DS1307RTC-1.4.1/DS1307RTC.h:19:22: error: 'tmElements_t' has not been declared

 static bool read(tmElements_t &tm);

                  ^~~~~~~~~~~~

C:\Users\brin8\Documents\Arduino\libraries\DS1307RTC-1.4.1/DS1307RTC.h:20:23: error: 'tmElements_t' has not been declared

 static bool write(tmElements_t &tm);

                   ^~~~~~~~~~~~

HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO:15:1: error: 'tmElements_t' does not name a type; did you mean 'timelib_month_t'?

tmElements_t tm;

^~~~~~~~~~~~

timelib_month_t

C:\Arduino_Projects\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO.ino: In function 'void setup()':

HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO:25:19: error: 'tm' was not declared in this scope

 if (RTC.write(tm)) {

               ^~

C:\Arduino_Projects\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO.ino:25:19: note: suggested alternative: 'Pm'

 if (RTC.write(tm)) {

               ^~

               Pm

C:\Arduino_Projects\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO.ino: In function 'bool getTime(const char*)':

HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO:58:3: error: 'tm' was not declared in this scope

tm.Hour = Hour;

^~

C:\Arduino_Projects\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO.ino:58:3: note: suggested alternative: 'Pm'

tm.Hour = Hour;

^~

Pm

C:\Arduino_Projects\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO.ino: In function 'bool getDate(const char*)':

HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO:75:3: error: 'tm' was not declared in this scope

tm.Day = Day;

^~

C:\Arduino_Projects\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO\HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO.ino:75:3: note: suggested alternative: 'Pm'

tm.Day = Day;

^~

Pm

HOW_TO_DO_DAILY_TASKS_WITH_ARDUINO:77:13: error: 'CalendarYrToTm' was not declared in this scope

tm.Year = CalendarYrToTm(Year);

         ^~~~~~~~~~~~~~

Multiple libraries were found for "TimeLib.h"

Used: C:\Users\brin8\Documents\Arduino\libraries\TimeLib-master

Not used: C:\Users\brin8\Documents\Arduino\libraries\Time

exit status 1

'tmElements_t' does not name a type; did you mean 'timelib_month_t'?

One of these libraries seems to be out of date or is otherwise inapplicable to your board.

This is where the (edited) sketch from post #1 originated (SetTime Sketch):

It calls for installing these two libraries:

Thanks, I'll reinstall libraries and make sure I use latest revisons.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.