From 532de484f28c3c6f5c4bc04a9d53e406ada2848b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 13 Apr 2018 13:51:39 +0200 Subject: [PATCH] Fix: List ids sorted --- bin/domain/imag-diary/src/list.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/bin/domain/imag-diary/src/list.rs b/bin/domain/imag-diary/src/list.rs index 158ef577..f1a8164f 100644 --- a/bin/domain/imag-diary/src/list.rs +++ b/bin/domain/imag-diary/src/list.rs @@ -26,6 +26,10 @@ use libimagerror::trace::MapErrTrace; use libimagerror::io::ToExitCode; use libimagerror::exit::ExitUnwrap; use libimagutil::debug_result::*; +use libimagdiary::diaryid::DiaryId; +use libimagdiary::diaryid::FromStoreId; +use libimagdiary::error::Result; + use util::get_diary_name; @@ -33,17 +37,21 @@ pub fn list(rt: &Runtime) { let diaryname = get_diary_name(rt) .unwrap_or_else(|| warn_exit("No diary selected. Use either the configuration file or the commandline option", 1)); - Diary::entries(rt.store(), &diaryname) + let mut ids = Diary::entries(rt.store(), &diaryname) .map_dbg_str("Ok") .map_err_trace_exit_unwrap(1) - .for_each(|id| { - writeln!(rt.stdout(), "{}", id - .without_base() - .to_str() - .map_err_trace() - .unwrap_or(String::from("<>"))) - .to_exit_code() - .unwrap_or_exit(); - }) + .map(|id| DiaryId::from_storeid(&id)) + .collect::>>() + .map_err_trace_exit_unwrap(1); + + ids.sort_by_key(|id| { + [id.year() as u32, id.month(), id.day(), id.hour(), id.minute(), id.second()] + }); + + for id in ids { + writeln!(rt.stdout(), "{}", id) + .to_exit_code() + .unwrap_or_exit(); + } }