From 316fe71133ef94b75321c5c1d2e92fe599d1109d Mon Sep 17 00:00:00 2001 From: Shannon Sterz Date: Tue, 4 Mar 2025 15:42:27 +0100 Subject: [PATCH] time: add new `epoch_to_http_date` helper this makes it easy to generate RFC9110 preferred HTTP Dates. Signed-off-by: Shannon Sterz --- proxmox-time/src/posix.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/proxmox-time/src/posix.rs b/proxmox-time/src/posix.rs index bb60ba04..79fcb1b6 100644 --- a/proxmox-time/src/posix.rs +++ b/proxmox-time/src/posix.rs @@ -380,6 +380,15 @@ pub fn epoch_to_rfc2822(epoch: i64) -> Result { Ok(rfc2822_date) } +/// Convert an epoch to an RFC9110 preferred HTTP Date format. +/// +/// see: +pub fn epoch_to_http_date(epoch: i64) -> Result { + 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| {