| 130 | } |
| 131 | |
| 132 | std::string FormatRFC1123DateTime(int64_t time) |
| 133 | { |
| 134 | if (time < -62167219200 || 253402300799 < time) { |
| 135 | // 4-digit year, so only support years 0 to 9999 |
| 136 | return ""; |
| 137 | } |
| 138 | const std::chrono::sys_seconds secs{std::chrono::seconds{time}}; |
| 139 | const auto days{std::chrono::floor<std::chrono::days>(secs)}; |
| 140 | const auto w{days.time_since_epoch().count() % 7}; // will be in the range [-6, 6] |
| 141 | std::string_view weekday{weekdays.at(w >= 0 ? w : w + 7)}; |
| 142 | const std::chrono::year_month_day ymd{days}; |
| 143 | std::string_view month{months.at(unsigned{ymd.month()} - 1)}; |
| 144 | const std::chrono::hh_mm_ss hms{secs - days}; |
| 145 | // examples: Mon, 27 Jul 2009 12:28:53 GMT |
| 146 | // Fri, 31 May 2024 19:18:04 GMT |
| 147 | return strprintf("%03s, %02u %03s %04i %02i:%02i:%02i GMT", weekday, unsigned{ymd.day()}, month, signed{ymd.year()}, hms.hours().count(), hms.minutes().count(), hms.seconds().count()); |
| 148 | } |
| 149 | |
| 150 | struct timeval MillisToTimeval(int64_t nTimeout) |
| 151 | { |