mygit

[UNMAINTAINED] A cgit/webgit alternative, written in Rust
Log | Files | Refs | README | LICENSE

commit 9d87d1bee5ac4d709bc46a4ac58c8dac398bea25
parent e4a2ea4ee1e0e966d227a02cdbcd2107c398900c
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 14 Mar 2021 11:55:52 -0700

Add timezone formatting

Diffstat:
Msrc/main.rs | 10+++++-----
Mtemplates/commit.html | 2+-
Mtemplates/log.html | 2+-
3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -201,11 +201,11 @@ async fn repo_commit(req: Request<()>) -> tide::Result { Ok(tmpl.into()) } mod filters { - pub fn iso_date(i: &i64) -> ::askama::Result<String> { - // UTC date - let datetime: chrono::DateTime<chrono::Utc> = - chrono::DateTime::from_utc(chrono::NaiveDateTime::from_timestamp(*i, 0), chrono::Utc); - Ok(datetime.format("%Y-%m-%d").to_string()) + pub fn format_datetime(time: &git2::Time, format: &str) -> ::askama::Result<String> { + use chrono::{FixedOffset, TimeZone}; + let offset = FixedOffset::west(time.offset_minutes() * 60); + let datetime = offset.timestamp(time.seconds(), 0); + Ok(datetime.format(format).to_string()) } pub fn unix_perms(m: &i32) -> ::askama::Result<String> { diff --git a/templates/commit.html b/templates/commit.html @@ -9,7 +9,7 @@ <br> <b>Author:</b> {{commit.author().name().unwrap()}} &lt;<a href="mailto:{{commit.author().email().unwrap()}}">{{commit.author().email().unwrap()}}</a>&gt; <br> - <b>Date:</b> {{commit.time().seconds()}} + <b>Date:</b> {{commit.time()|format_datetime("%c %z")}} <br> {% let stats = diff.stats().unwrap() %} {{stats.files_changed()}} files changed; {{stats.insertions()}} insertions {{stats.deletions()}} deletions diff --git a/templates/log.html b/templates/log.html @@ -10,7 +10,7 @@ {% let summary = commit.summary().unwrap_or("")|truncate(72) %} <td>{{summary}}</td> <td><a href="mailto:{{commit.author().email().unwrap_or("")}}">{{commit.author().name().unwrap_or("")}}</a></td> - <td>{{commit.time().seconds()|iso_date}}</td> + <td>{{commit.time()|format_datetime("%Y-%m-%d")}}</td> </tr> {% endfor %} </table>