Skip to content

Commit f2e3252

Browse files
author
Per-Gunnar Eriksson
committed
Daily reporting fix apparently :(
1 parent b1c491a commit f2e3252

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/storage.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,15 @@ pub fn entries_to_activities(
144144
let start_date = start_time.date_naive();
145145
let end_date = end_time.date_naive();
146146

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) {
147+
// FIX: Always limit activities to end of day when they span across different days,
148+
// regardless of whether the next entry is a midnight separator or not
149+
if start_date != end_date {
150150
// Create an end of day time (23:59:59) for the start date
151151
let end_of_day = Local
152152
.from_local_datetime(
153153
&start_date.and_hms_opt(23, 59, 59).unwrap()
154154
)
155+
.single()
155156
.unwrap();
156157

157158
// Create activity that ends at the end of the day
@@ -164,6 +165,30 @@ pub fn entries_to_activities(
164165
);
165166

166167
activities.push(activity);
168+
169+
// If the next entry isn't a midnight separator or hello entry,
170+
// create another activity for the following day that starts at 00:00:00
171+
if !entries[i+1].name.starts_with(MIDNIGHT_SEPARATOR_PREFIX) &&
172+
entries[i+1].name != HELLO_ENTRY_NAME {
173+
// Start of day time (00:00:00) for the end date
174+
let start_of_day = Local
175+
.from_local_datetime(
176+
&end_date.and_hms_opt(0, 0, 0).unwrap()
177+
)
178+
.single()
179+
.unwrap();
180+
181+
// Create continuation activity that starts at beginning of next day
182+
let continuation_activity = Activity::new(
183+
entries[i].name.clone(),
184+
start_of_day,
185+
end_time,
186+
false,
187+
entries[i].comment.clone(),
188+
);
189+
190+
activities.push(continuation_activity);
191+
}
167192
} else {
168193
// Create activity using the CURRENT entry's name
169194
// This represents what you were doing during this time span

0 commit comments

Comments
 (0)