[pdm-devel] [PATCH proxmox v4 01/21] time: add new `epoch_to_http_date` helper
Shannon Sterz
s.sterz at proxmox.com
Tue Mar 4 13:04:46 CET 2025
this makes it easy to generate RFC9110 preferred HTTP Dates.
Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
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<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| {
--
2.39.5
More information about the pdm-devel
mailing list