ropg / ezTime

ezTime — pronounced "Easy Time" — is a very easy to use Arduino time and date library that provides NTP network time lookups, extensive timezone support, formatted time and date strings, user events, millisecond precision and more.
MIT License
327 stars 92 forks source link

makeOrdinalTime #68

Open clydde opened 4 years ago

clydde commented 4 years ago

Help!!!

Can anyone confirm me that this example code works? I took a couple of hours and although at some point a week ago it worked, I did not get it working.

I tried it with different versions from 0.7 to the current one, but nothing ¿?

Flash on ESP32

/*
 * This sketch prints a message at noon UTC, every second Tuesday of the month. 
 * Not very useful, but demonstrates events and ordinal time.
 */

#include <ezTime.h>
#include <WiFi.h>

void setup() {

    Serial.begin(115200);
    while (!Serial) { ; }       // wait for Serial port to connect. Needed for native USB port only
    WiFi.begin("your-ssid", "your-password");

    waitForSync();

    // Set the event to trigger for the first time
    setEvent( itIsTheSecondTuesday, nextSecondTuesday() );

}

void loop() {

    events();

}

void itIsTheSecondTuesday() {
    Serial.print(F("It's the second Tuesday: "));
    Serial.println(UTC.dateTime());

    // The event then sets a new event for the next time
    setEvent( itIsTheSecondTuesday, nextSecondTuesday() );
}

time_t nextSecondTuesday() {

    int8_t m = UTC.month();
    int16_t y = UTC.year();
    time_t t = 0;

    while (t <= UTC.now()) {
        // Try in current month first, if that has passed, loop once more for next month
        //t = makeOrdinalTime(12, 0, 0, SECOND, TUESDAY, m, y);

             t = makeOrdinalTime(18, 28, 0, FIRST, MONDAY, m, y);
        m++;
        if (m == 13) {
            m = 1;
            y++;
        }
    }
    return t;
}