diff --git a/Cargo.lock b/Cargo.lock index 352ce5a..a1cb323 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,10 +122,23 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "chrono" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" +dependencies = [ + "num-integer", + "num-traits", + "serde", + "time", +] + [[package]] name = "client" version = "0.1.0" dependencies = [ + "chrono", "futures 0.3.4", "seed", "serde", @@ -407,6 +420,7 @@ name = "git-social" version = "0.1.0" dependencies = [ "async-std", + "chrono", "git2", "serde", "serde_derive", @@ -773,6 +787,25 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "num-integer" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.12.0" @@ -1040,6 +1073,7 @@ dependencies = [ name = "shared" version = "0.1.0" dependencies = [ + "chrono", "serde", "serde_derive", "serde_json", diff --git a/client/Cargo.toml b/client/Cargo.toml index be4c831..2e18e85 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] +chrono = "*" shared = { path = "../shared" } seed = "^0.6.0" wasm-bindgen = "^0.2.50" diff --git a/client/src/lib.rs b/client/src/lib.rs index 1ca9307..ecc9582 100755 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -61,15 +61,15 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders) { } fn commit_to_dom(commit: &SocialCommit) -> Vec> { - nodes![ + nodes![div![ p!(format!( "Author: {} <{}>", commit.author.name, commit.author.email )), - p!(format!("Date: {}", commit.time)), + span!(format!("Date: {}", commit.time)), p!(format!(" {}", commit.message.replace("\n", "\n "))), hr![], - ] + ]] } fn tree_entry_to_dom(te: &SocialTreeEntry) -> Vec> { nodes![p![format!("{:o} | {}", te.filemode, te.name)], hr![],] diff --git a/server/Cargo.toml b/server/Cargo.toml index e45ecbb..3ae43a6 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dependencies] async-std = "*" +chrono = { version = "*", features = ["serde"] } serde = "*" serde_derive = "*" serde_json = "*" diff --git a/server/src/git/commit.rs b/server/src/git/commit.rs index 6e1c42c..9bafb6a 100644 --- a/server/src/git/commit.rs +++ b/server/src/git/commit.rs @@ -1,5 +1,6 @@ use crate::git::repo::SocialRepo; use crate::git::Error; +use chrono::offset::{Local, TimeZone}; use git2::{Commit, Signature}; use shared::{SocialCommit, SocialSignature}; @@ -7,14 +8,14 @@ fn into_social_signature<'a>(s: Signature<'a>) -> SocialSignature { SocialSignature { name: s.name().unwrap_or("").to_owned(), email: s.email().unwrap_or("").to_owned(), - when: s.when().seconds(), + when: Local.timestamp(s.when().seconds(), 0), } } fn into_social_commit<'repo>(c: Commit<'repo>) -> SocialCommit { SocialCommit { id: format!("{}", c.id()), - time: c.time().seconds(), + time: Local.timestamp(c.time().seconds(), 0), message: c.message().unwrap_or("").to_owned(), author: into_social_signature(c.author()), committer: into_social_signature(c.committer()), diff --git a/server/src/git/diff.rs b/server/src/git/diff.rs index 8f5661d..68b2586 100644 --- a/server/src/git/diff.rs +++ b/server/src/git/diff.rs @@ -13,7 +13,8 @@ fn into_social_diff<'a>(d: Diff<'a>) -> SocialDiff { lines.push("? cannot convert utf8 string on this line!".to_string()); } true - }); + }) + .unwrap_or(()); SocialDiff { lines } } diff --git a/shared/Cargo.toml b/shared/Cargo.toml index aaebf1d..5d27fea 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Vladan Popovic "] edition = "2018" [dependencies] +chrono = { version = "*", features = ["serde"] } serde = "*" serde_derive = "*" serde_json = "*" diff --git a/shared/src/lib.rs b/shared/src/lib.rs index bd91921..523b072 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -1,8 +1,10 @@ +use chrono::offset::Local; +use chrono::DateTime; use serde_derive::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SocialSignature { - pub when: i64, + pub when: DateTime, pub name: String, pub email: String, } @@ -10,7 +12,7 @@ pub struct SocialSignature { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SocialCommit { pub id: String, - pub time: i64, + pub time: DateTime, pub message: String, pub author: SocialSignature, pub committer: SocialSignature,