diff --git a/WOPR_Display_V2/utc_offset.h b/WOPR_Display_V2/utc_offset.h index 19eba82..7a44c6f 100644 --- a/WOPR_Display_V2/utc_offset.h +++ b/WOPR_Display_V2/utc_offset.h @@ -19,47 +19,36 @@ //=========================================================================== #include +#include String GetSecondsUntilXmas() { - HTTPClient http; - int httpCode = -1; - char szTemp[] = "https://christmas-days.anvil.app/_/api/get_days"; + struct tm *xmas; + time_t now = time(NULL); - http.begin(szTemp); - httpCode = http.GET(); //send GET request - if (httpCode != 200) - { - http.end(); - } - else - { - const char *s; - int i; - String payload = http.getString(); - http.end(); - - // Payload exmaple: {"Days to Christmas":265} - - // Serial.print("Response: "); - // erial.println(payload); - - int colon = payload.indexOf(":"); - int bracket = payload.indexOf("}"); + xmas = localtime(&now); - int days = payload.substring(colon + 1, bracket).toInt(); - - if (days > -1) - { - unsigned long seconds = (unsigned long)days * 24 * 60 * 60; - // Serial.print("Seconds: "); - // Serial.println(seconds); - return String(seconds) + " Seconds until XMAS..."; - } + // + // are we on/after Christmas, go to next year + // + if ((xmas->tm_mon == 11) && + (xmas->tm_mday >= 25)) { + xmas->tm_year++; + } - } // if successfully connected + // tm_mon (0-11), tm_mday(1-31) + xmas->tm_mon = 11; + xmas->tm_mday = 25; + xmas->tm_hour = 0; + xmas->tm_min = 0; + xmas->tm_sec = 0; - return "Failed to get seconds until Xmas"; + // convert to seconds + time_t xmasTime = mktime(xmas); + + unsigned long seconds = xmasTime - now; + + return String(seconds) + " Seconds until XMAS..."; } /* GetDaysUntilXmas() */ int GetTimeOffset(char *szIP)