Skip to content

Commit b1c491a

Browse files
author
Per-Gunnar Eriksson
committed
Fix reporting AGAIN
1 parent 869512e commit b1c491a

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

src/storage.rs

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,43 @@ pub fn entries_to_activities(
140140
let start_time = entries[i].datetime;
141141
let end_time = entries[i+1].datetime;
142142

143-
// Create activity using the CURRENT entry's name
144-
// This represents what you were doing during this time span
145-
let activity = Activity::new(
146-
entries[i].name.clone(),
147-
start_time,
148-
end_time,
149-
false,
150-
entries[i].comment.clone(),
151-
);
143+
// Check if this spans across days
144+
let start_date = start_time.date_naive();
145+
let end_date = end_time.date_naive();
152146

153-
activities.push(activity);
147+
// If the entries span across different days and the next entry isn't a midnight separator,
148+
// we should limit this activity to the end of the day (23:59:59)
149+
if start_date != end_date && !entries[i+1].name.starts_with(MIDNIGHT_SEPARATOR_PREFIX) {
150+
// Create an end of day time (23:59:59) for the start date
151+
let end_of_day = Local
152+
.from_local_datetime(
153+
&start_date.and_hms_opt(23, 59, 59).unwrap()
154+
)
155+
.unwrap();
156+
157+
// Create activity that ends at the end of the day
158+
let activity = Activity::new(
159+
entries[i].name.clone(),
160+
start_time,
161+
end_of_day,
162+
false,
163+
entries[i].comment.clone(),
164+
);
165+
166+
activities.push(activity);
167+
} else {
168+
// Create activity using the CURRENT entry's name
169+
// This represents what you were doing during this time span
170+
let activity = Activity::new(
171+
entries[i].name.clone(),
172+
start_time,
173+
end_time,
174+
false,
175+
entries[i].comment.clone(),
176+
);
177+
178+
activities.push(activity);
179+
}
154180
}
155181

156182
// Handle the last entry separately - it represents what you're currently doing
@@ -199,9 +225,16 @@ pub fn filter_entries_by_date_range(entries: &[Entry], start_date: NaiveDate, en
199225
// Find the last entry before the start date (needed for calculating the first activity's duration)
200226
// This handles the case where an activity starts before our date range but ends within it
201227
let mut last_entry_before_range = None;
228+
229+
// Only include the last entry before the range if it's from the same day as the start date
230+
// This prevents including entries from days or weeks ago
202231
for entry in entries.iter().rev() {
203-
if entry.datetime.date_naive() < start_date {
204-
last_entry_before_range = Some(entry.clone());
232+
let entry_date = entry.datetime.date_naive();
233+
if entry_date < start_date {
234+
// Only include if it's from the day before the start date
235+
if entry_date == start_date.pred_opt().unwrap() {
236+
last_entry_before_range = Some(entry.clone());
237+
}
205238
break;
206239
}
207240
}

0 commit comments

Comments
 (0)