diff --git a/lib/core/core/cli/dbex.rs b/lib/core/core/cli/dbex.rs index a7e91a6024f11f7f4db867cab77ccc9857b9ae06..12fb9196b70c1f26aaebf191080b05692b661389 100644 --- a/lib/core/core/cli/dbex.rs +++ b/lib/core/core/cli/dbex.rs @@ -76,6 +76,9 @@ pub struct MembersOpt { #[structopt(short = "e", long = "expire")] /// show members expire date pub expire: bool, + /// human readable output + #[structopt(short = "h", long = "human")] + pub human_readable: bool, } #[derive(StructOpt, Debug, Clone)] diff --git a/lib/core/core/lib.rs b/lib/core/core/lib.rs index f97e6a977845a89c1ac77f3ef5744c231da2ec5e..7e3ed04bfa24bf41cf1115908139bcc814c0c172 100644 --- a/lib/core/core/lib.rs +++ b/lib/core/core/lib.rs @@ -322,7 +322,10 @@ impl<'a, 'b: 'a> DuniterCore<'b, 'a, DuRsConf> { profile.as_str(), &conf, opts.csv, - &DBExQuery::WotQuery(DBExWotQuery::ExpireMembers(members_opts.reverse)), + &DBExQuery::WotQuery(DBExWotQuery::ExpireMembers( + members_opts.reverse, + members_opts.human_readable, + )), ); } else { dbex( diff --git a/lib/modules/blockchain/blockchain/Cargo.toml b/lib/modules/blockchain/blockchain/Cargo.toml index 5cfd27b861408fa8cbf9c7309e049d9e6f869b80..1a727f451f42d4689b9aee22824180f71e760b54 100644 --- a/lib/modules/blockchain/blockchain/Cargo.toml +++ b/lib/modules/blockchain/blockchain/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" path = "src/lib.rs" [dependencies] +chrono = "0.4.6" dirs = "1.0.2" duniter-conf = { path = "../../../core/conf" } dup-crypto = { path = "../../../tools/crypto" } diff --git a/lib/modules/blockchain/blockchain/src/dbex.rs b/lib/modules/blockchain/blockchain/src/dbex.rs index 6cfca059fe7ff64d670762e6325115af91847f82..9eb082e074c162865bdf2e82d06eae77b8718e62 100644 --- a/lib/modules/blockchain/blockchain/src/dbex.rs +++ b/lib/modules/blockchain/blockchain/src/dbex.rs @@ -14,6 +14,8 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::*; + +use chrono::prelude::*; use dubp_documents::documents::transaction::*; use duniter_module::DuniterConf; use dup_crypto::keys::*; @@ -28,7 +30,7 @@ pub enum DBExWotQuery { /// Ask distance of all members AllDistances(bool), /// Show members expire date - ExpireMembers(bool), + ExpireMembers(bool, bool), /// Show members list ListMembers(bool), /// Ask member datas @@ -228,7 +230,7 @@ pub fn dbex_wot<DC: DuniterConf>(profile: &str, conf: &DC, csv: bool, query: &DB compute_distances_duration.subsec_millis() ); } - DBExWotQuery::ExpireMembers(ref reverse) => { + DBExWotQuery::ExpireMembers(reverse, human_readable) => { // Open blockchain database let blockchain_db = open_file_db::<LocalBlockchainV10Datas>(&db_path, "blockchain.db") .expect("Fail to open blockchain db"); @@ -263,13 +265,19 @@ pub fn dbex_wot<DC: DuniterConf>(profile: &str, conf: &DC, csv: bool, query: &DB expire_dates }) .expect("Fail to read ms db"); - if *reverse { + if reverse { expire_dates.sort_unstable_by(|(_, d1), (_, d2)| d1.cmp(&d2)); } else { expire_dates.sort_unstable_by(|(_, d1), (_, d2)| d2.cmp(&d1)); } for (node_id, expire_date) in expire_dates { - println!("{}, {}", wot_uid_index[&node_id], expire_date); + if human_readable { + let datetime = NaiveDateTime::from_timestamp(expire_date as i64, 0); + let human_expire_date = datetime.format("%Y-%m-%d %H:%M:%S UTC"); + println!("{}, {}", wot_uid_index[&node_id], human_expire_date); + } else { + println!("{}, {}", wot_uid_index[&node_id], expire_date); + } } } DBExWotQuery::MemberDatas(ref uid) => {