Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Added total hours to the grouped list (thanks to [@Niatross](https://github.com/Niatross))
- Update of libc:musl to support longarch64 (thanks to [@zhaixiaojuan](https://github.com/zhaixiaojuan))
- Improved general `--help` output (thanks to [@RossBarnie](https://github.com/RossBarnie))

Expand Down
4 changes: 2 additions & 2 deletions src/data/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ mod tests {
start: date(2024, 3, 19),
end: None,
};
return vec![a0, a1, a2, a3, a4];
vec![a0, a1, a2, a3, a4]
}

fn date(year: i32, month: u32, day: u32) -> NaiveDateTime {
let date = NaiveDate::from_ymd_opt(year, month, day).unwrap();
return NaiveDateTime::new(date, chrono::NaiveTime::from_hms_opt(10, 0, 0).unwrap());
NaiveDateTime::new(date, chrono::NaiveTime::from_hms_opt(10, 0, 0).unwrap())
}
}
2 changes: 1 addition & 1 deletion src/data/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn filter_activities<'a>(
.filter(move |activity| {
filter
.project
.map_or(true, |p| WildMatch::new(p).matches(&activity.project))
.is_none_or(|p| WildMatch::new(p).matches(&activity.project))
})
.collect()
}
Expand Down
15 changes: 13 additions & 2 deletions src/view/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::collections::BTreeMap;
use crate::conf;
use crate::data::activity;
use crate::view::format_util;
use crate::view::report;
use crate::view::table;

// displays a table with activities
Expand Down Expand Up @@ -73,7 +74,17 @@ fn create_activities_group(title: &str, activities: &[&activity::Activity]) -> t
.iter()
.map(|a| get_activity_table_row(a, false))
.collect();
table::Group::new(Some(title.to_string()), rows)

let total_duration = report::sum_duration(activities);

table::Group::new(
Some(format!(
"{}\t{}",
title,
format_util::format_duration(&total_duration)
)),
rows,
)
}

// displays a table with running activities (no end time)
Expand Down Expand Up @@ -170,7 +181,7 @@ pub fn list_descriptions_and_projects_with_index(
fn get_activity_table_row(activity: &activity::Activity, with_start_dates: bool) -> table::Row {
let more_then_one_day = activity
.end
.map_or(false, |end| activity.start.date() != end.date());
.is_some_and(|end| activity.start.date() != end.date());

let display_end = activity.end.map_or_else(
|| "-".to_string(),
Expand Down
10 changes: 5 additions & 5 deletions src/view/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a> Report<'a> {
}
}

impl<'a> fmt::Display for Report<'a> {
impl fmt::Display for Report<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut longest_line = get_longest_line(&self.project_map).unwrap_or(0);
let longest_duration_string = get_longest_duration_string(self).unwrap_or(0);
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn show_activities<'a>(activities: &'a [&'a activity::Activity]) {
println!("\n{report}");
}

fn create_project_map<'a>(activities: &'a [&'a activity::Activity]) -> ProjectMap {
fn create_project_map<'a>(activities: &'a [&'a activity::Activity]) -> ProjectMap<'a> {
let mut project_map: ProjectMap = BTreeMap::new();

for a in activities {
Expand All @@ -79,7 +79,7 @@ fn create_project_map<'a>(activities: &'a [&'a activity::Activity]) -> ProjectMa
project_map
}

fn sum_duration(activities: &[&activity::Activity]) -> Duration {
pub fn sum_duration(activities: &[&activity::Activity]) -> Duration {
let mut duration = Duration::seconds(0);

for activity in activities {
Expand Down Expand Up @@ -172,8 +172,8 @@ fn print_total_duration(

fn group_activities_by_description<'a>(
activities: &'a [&'a activity::Activity],
) -> BTreeMap<&str, Vec<&'a activity::Activity>> {
let mut activity_map: BTreeMap<&str, Vec<&'a activity::Activity>> = BTreeMap::new();
) -> BTreeMap<&'a str, Vec<&'a activity::Activity>> {
let mut activity_map: BTreeMap<&'a str, Vec<&'a activity::Activity>> = BTreeMap::new();

for a in activities {
activity_map.entry(&a.description).or_default().push(a);
Expand Down
6 changes: 3 additions & 3 deletions src/view/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl StatusReportWriter for StatusReport {
}
}

impl<'a> fmt::Display for StatusReportData<'a> {
impl fmt::Display for StatusReportData<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let longest_line = 30;
print_title(f, self.project)?;
Expand Down Expand Up @@ -236,7 +236,7 @@ mod tests {

fn clean(a: &str) -> String {
let st_f = "\u{1b}[0m\u{1b}";
let clean_res = a.replace(st_f, "<>");
clean_res

a.replace(st_f, "<>")
}
}
Loading