From b02d4a03a7037848ec910c3a66380a1f6b4889ef Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Tue, 28 Jun 2016 01:39:35 +0300 Subject: [PATCH] allow last modified to be also set to time_t or current time to start sntp: ```cpp void startSNTP(){ time_t rawtime; configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov"); while(time(&rawtime) == 0) delay(10); } ``` --- src/WebHandlerImpl.h | 2 ++ src/WebHandlers.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/WebHandlerImpl.h b/src/WebHandlerImpl.h index 4d1463c..0dbc9f4 100644 --- a/src/WebHandlerImpl.h +++ b/src/WebHandlerImpl.h @@ -49,6 +49,8 @@ class AsyncStaticWebHandler: public AsyncWebHandler { AsyncStaticWebHandler& setCacheControl(const char* cache_control); AsyncStaticWebHandler& setLastModified(const char* last_modified); AsyncStaticWebHandler& setLastModified(struct tm* last_modified); + AsyncStaticWebHandler& setLastModified(time_t last_modified); + AsyncStaticWebHandler& setLastModified(); //sets to current time. Make sure sntp is runing and time is updated }; class AsyncCallbackWebHandler: public AsyncWebHandler { diff --git a/src/WebHandlers.cpp b/src/WebHandlers.cpp index 4dc5613..a77ee0e 100644 --- a/src/WebHandlers.cpp +++ b/src/WebHandlers.cpp @@ -68,6 +68,17 @@ AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(struct tm* last_mo return setLastModified((const char *)result); } +AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(time_t last_modified){ + return setLastModified((struct tm *)gmtime(&last_modified)); +} + +AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(){ + time_t last_modified; + if(time(&last_modified) == 0) //time is not yet set + return *this; + return setLastModified(last_modified); +} + bool AsyncStaticWebHandler::canHandle(AsyncWebServerRequest *request) { if (request->method() == HTTP_GET &&