Repository: redlib-org/redlib (language: rust)

Issue:
🐛 Bug Report: Rss feeds is missing timestamps
## Describe the bug
Rss feeds is missing timestamps (`<pubDate>` tag).

## Steps to reproduce the bug

1. Load a rss from your local instance in a rss reader (example https://redlib.zaggy.nl/r/emulation.rss)
2. Notice all entries displays as the current time, or without time depending on your rss reader.

## What's the expected behavior?
The time of the posts should be scraped and exported in the rss feed.

<!-- Mandatory -->
- [x] I checked that the instance that this was reported on is running the latest git commit, or I can reproduce it locally on the latest git commit


Discussion / hints:

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index 20d528b1..24791b44 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -274,9 +274,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
 [[package]]
 name = "chrono"
-version = "0.4.38"
+version = "0.4.39"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
+checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825"
 dependencies = [
  "num-traits",
 ]
@@ -1367,6 +1367,7 @@ dependencies = [
  "brotli",
  "build_html",
  "cached",
+ "chrono",
  "clap",
  "common-words-all",
  "cookie",
diff --git a/Cargo.toml b/Cargo.toml
index a4d01703..843b9c9b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -51,6 +51,7 @@ common-words-all = { version = "0.0.2", default-features = false, features = ["e
 hyper-rustls = { version = "0.24.2", features = [ "http2" ] }
 tegen = "0.1.4"
 serde_urlencoded = "0.7.1"
+chrono = { version = "0.4.39", default-features = false, features = [ "std" ] }
 htmlescape = "0.3.1"
 
 
diff --git a/src/subreddit.rs b/src/subreddit.rs
index 2362a124..d5d51961 100644
--- a/src/subreddit.rs
+++ b/src/subreddit.rs
@@ -11,6 +11,7 @@ use hyper::{Body, Request, Response};
 use log::{debug, trace};
 use rinja::Template;
 
+use chrono::DateTime;
 use once_cell::sync::Lazy;
 use regex::Regex;
 use time::{Duration, OffsetDateTime};
@@ -607,6 +608,7 @@ pub async fn rss(req: Request<Body>) -> Result<Response<Body>, String> {
 					link: Some(utils::get_post_url(&post)),
 					author: Some(post.author.name),
 					content: Some(rewrite_urls(&post.body)),
+					pub_date: Some(DateTime::from_timestamp(post.created_ts as i64, 0).unwrap_or_default().to_rfc2822()),
 					description: Some(format!(
 						"<a href='{}{}'>Comments</a>",
 						config::get_setting("REDLIB_FULL_URL").unwrap_or_default(),
diff --git a/src/user.rs b/src/user.rs
index 50a4daa1..2fb8b0d1 100644
--- a/src/user.rs
+++ b/src/user.rs
@@ -5,6 +5,7 @@ use crate::client::json;
 use crate::server::RequestExt;
 use crate::utils::{error, filter_posts, format_url, get_filters, nsfw_landing, param, setting, template, Post, Preferences, User};
 use crate::{config, utils};
+use chrono::DateTime;
 use hyper::{Body, Request, Response};
 use rinja::Template;
 use time::{macros::format_description, OffsetDateTime};
@@ -165,6 +166,7 @@ pub async fn rss(req: Request<Body>) -> Result<Response<Body>, String> {
 					title: Some(post.title.to_string()),
 					link: Some(utils::get_post_url(&post)),
 					author: Some(post.author.name),
+					pub_date: Some(DateTime::from_timestamp(post.created_ts as i64, 0).unwrap_or_default().to_rfc2822()),
 					content: Some(rewrite_urls(&post.body)),
 					..Default::default()
 				})


Test patch: