|
@@ -16,25 +16,47 @@
|
|
|
static httpd_handle_t httpd;
|
|
|
|
|
|
#define TIMEBUF_LEN 32
|
|
|
-static const char *http_date(time_t when, char *timebuf)
|
|
|
+static const char *http_date(const struct tm *when)
|
|
|
{
|
|
|
+ static char timebuf[TIMEBUF_LEN];
|
|
|
+
|
|
|
strftime(timebuf, TIMEBUF_LEN,
|
|
|
- "%a, %d %b %Y %H:%M:%S GMT", gmtime(&when));
|
|
|
+ "%a, %d %b %Y %H:%M:%S GMT", when);
|
|
|
|
|
|
return timebuf;
|
|
|
}
|
|
|
|
|
|
static const char *http_now(void)
|
|
|
{
|
|
|
- static char timebuf[TIMEBUF_LEN];
|
|
|
- return http_date(time(NULL), timebuf);
|
|
|
+ time_t t = time(NULL);
|
|
|
+ return http_date(gmtime(&t));
|
|
|
+}
|
|
|
+
|
|
|
+static struct tm *set_weekday(struct tm *tm)
|
|
|
+{
|
|
|
+ /*
|
|
|
+ * A variation on Zeller's congruence.
|
|
|
+ */
|
|
|
+ unsigned int c, y, m, d;
|
|
|
+
|
|
|
+ y = tm->tm_year + 1900;
|
|
|
+ m = tm->tm_mon + 2;
|
|
|
+ d = tm->tm_mday;
|
|
|
+
|
|
|
+ if (m < 4) {
|
|
|
+ m += 12;
|
|
|
+ y--;
|
|
|
+ }
|
|
|
+
|
|
|
+ c = y/100;
|
|
|
+
|
|
|
+ tm->tm_wday = (d + ((13*m)/5) + y + (y >> 2) - c + (c >> 2) + 6) % 7;
|
|
|
+ return tm;
|
|
|
}
|
|
|
|
|
|
static const char *http_dos_date(uint32_t dos_date)
|
|
|
{
|
|
|
- static char timebuf[TIMEBUF_LEN];
|
|
|
struct tm tm;
|
|
|
- time_t t;
|
|
|
|
|
|
tm.tm_sec = (dos_date << 1) & 63;
|
|
|
tm.tm_min = (dos_date >> 5) & 63;
|
|
@@ -42,9 +64,9 @@ static const char *http_dos_date(uint32_t dos_date)
|
|
|
tm.tm_mday = (dos_date >> 16) & 31;
|
|
|
tm.tm_mon = ((dos_date >> 21) & 15) - 1;
|
|
|
tm.tm_year = (dos_date >> 25) + 80;
|
|
|
- tm.tm_isdst = -1;
|
|
|
+ tm.tm_isdst = 0; /* Times are stored in GMT */
|
|
|
|
|
|
- return http_date(mktime(&tm), timebuf);
|
|
|
+ return http_date(set_weekday(&tm));
|
|
|
}
|
|
|
|
|
|
static esp_err_t httpd_error(httpd_req_t *req,
|