ESP32 setenv() error

I built a project that works. Then I made a copy of the project into a new directory and started my second project based on that. The second projects adds more functionality unrelated to time.
I get the error “identifier "setenv" is undefined” as I didn’t for the first project.
The files are copies of the original projects! so all the stuff from the 1st project, are in the second project with no errors!
I googled the problem and no solution was found.
The code snippet ;
void StartTime(){
configTime(0, 0, “”, “”);
setenv(“TZ”, Timezone, 1); //from const char* Timezone = “EST5EDT,M3.2.0,M11.1.0”; // EST USA
Time_format = “M”;
I’ve tried everything I can think of during the past 2 days, with no luck.
Any help would be appreciated.

As a compile error or an IntelliSense error?

Thanks for the quick reply.
Only an IntelliSense error. Generated the code, but the time is always London time as if Timezone = “EST5EDT,M3.2.0,M11.1.0”; statement had no effect. Changing it to other time zones won’t make a difference.
Thanks for your help.

The intellisense error part of this topic is a duplicate of Identifier is undefined - setenv tzset.

The not working during runtime is another issue. Assuming this is a ESP32 project, have you tried using the latest Arduino-ESP32 by setting platform = in the platformio.ini?

Yes I read the original post on that.
I just tried that by replacing the line “platform = espressif32” with yours.
Made no difference.
How come it works on the original project and not this one? That part has me stumped.

Does it also not work in the Arduino the way you do it in the new project?

I haven’t tried that because, why would it work on one but not the other?
If it didn’t work on either, I’d say I’m doing something wrong.
I’ll give your suggestion a try and will get back to you.

It compiles without any error in Arduino IDE.
I’ve also tried “Time.h” and <Time.h> with no luck.
It’s strange that I can’t get the definition for setenv() via F2 in platformIO, even when there is no errors at compile time!

So you have one minimal sketch that tries to set the timezone as you want and it does work during runtime when flashed via the the Arduino IDE, but the exact same piece of code fails during runtime in PlatofrmIO?

No. My first sketch compiles and runs correct on PlatformIO.
My second sketch was a new platformIO based project made from a copy of the second. I added some functions to the second version and kept the 1st version as a working backup.
The 1st gets the correct time, the second gives an error, but still links and creates an executable that I uploaded to the ESP32. It reads the time in greenwich time.
Then you suggested trying to compile it under ArduinoIDE (considered 3rd version, from copy pasting the second version onto the ArduinoIDE). This third version has no problems running under ArduinIDE.
Do you see why I’m stumped?

I have this bodge in a globals.h file which cures that issue.

//intellisense workaround
_VOID      _EXFUN(tzset,    (_VOID));
int _EXFUN(setenv,(const char *__string, const char *__value, int __overwrite));

But it doesn’t cause a problem.
Here is the UK call I make

configTime(0 * 3600, 0, "", "");
setenv("TZ", "GMT+0BST-1,M3.5.0/01:00:00,M10.5.0/02:00:00", 1);

getting the time:

    time_t now = time(nullptr);
    str_time = String(ctime(&now));

    struct tm *timeinfo;
    timeinfo = localtime(&now);
    int current_minute = timeinfo->tm_hour * 60 + timeinfo->tm_min;

    Dusk2Dawn home(LOCATION_LAT, LOCATION_LON, 0);

    int sunrise_minute = home.sunrise(timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_isdst);
    int sunset_minute = home.sunset(timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_isdst);

    is_day = false;
    if (current_minute >= sunrise_minute && current_minute <= sunset_minute)
      is_day = true;

I basically just grab the time and work out if its after sunset or not.

Thanks for your reply.
I am not concerned with intellisense not working right.
It compiles and runs, but changes to setenv(), makes no difference and it always returns UK time.
The 2nd project is an exact copy and paste of the 1st project, into a new project directory, but gives this error and still compiles and links fine!
I’ve moved on to other parts of development. I can always deduct 5 hours and get the local time, but I will have to find a solution later.
Thanks for your input.

Thats annoying, all I can suggest is that its not understanding your TS string. Mines obviously been butchered but I got there in the end. I saw a lot of TZ strings on the net that were all wrong.

What if you put nonsense in there?

The irony is that I couldn’t get it to give me the UK local time - I think I was getting UTC which just happens to be the same as UK local time for 6 months of the year.