Skip to main content

codeberg_cli/render/
comment.rs

1use time::{OffsetDateTime, format_description};
2
3pub fn render_comment(username: &str, creation_time: &OffsetDateTime, comment: &str) -> String {
4    const PARENTHESES: usize = 2;
5    const COLON: usize = 1;
6
7    let creation_time_formatted = creation_time
8        .format(
9            &format_description::parse("[day].[month].[year] - [hour]:[minute]")
10                .expect("invalid DateTime format"),
11        )
12        .expect("Couldn't format DateTime'");
13
14    format!(
15        "{}\n({}):\n{}\n\n{}",
16        username,
17        creation_time_formatted,
18        "=".repeat(creation_time_formatted.len() + PARENTHESES + COLON),
19        comment
20    )
21}