Ok(epoch)
}
+/// Convert Unix epoch into RFC2822 local time with TZ
+pub fn epoch_to_rfc2822(epoch: i64) -> Result<String, Error> {
+ let localtime = localtime(epoch)?;
+ let locale = Locale::new(libc::LC_ALL, Locale::C)?;
+ let rfc2822_date = strftime_l("%a, %d %b %Y %T %z", &localtime, &locale)?;
+
+ Ok(rfc2822_date)
+}
+
#[test]
fn test_leap_seconds() {
let convert_reconvert = |epoch| {
assert_eq!(formatted, "Tue, 29 Dec 2020 17:30:00 +0000");
}
+
+#[test]
+fn test_epoch_to_rfc2822() {
+ let epoch = 1609263000;
+ // Output is TZ-dependent, so only verify that it did not fail.
+ // Internally, it uses strftime_l which we test already.
+ assert!(epoch_to_rfc2822(epoch).is_ok());
+}