time: add new epoch_to_http_date helper

this makes it easy to generate RFC9110 preferred HTTP Dates.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
This commit is contained in:
Shannon Sterz 2025-03-04 15:42:27 +01:00 committed by Wolfgang Bumiller
parent 68b1396553
commit 316fe71133

View File

@ -380,6 +380,15 @@ pub fn epoch_to_rfc2822(epoch: i64) -> Result<String, Error> {
Ok(rfc2822_date)
}
/// Convert an epoch to an RFC9110 preferred HTTP Date format.
///
/// see: <https://httpwg.org/specs/rfc9110.html#http.date>
pub fn epoch_to_http_date(epoch: i64) -> Result<String, Error> {
let gmtime = gmtime(epoch)?;
let locale = Locale::new(libc::LC_ALL, Locale::C)?;
strftime_l("%a, %d %b %Y %H:%M:%S GMT", &gmtime, &locale)
}
#[test]
fn test_leap_seconds() {
let convert_reconvert = |epoch| {