commit a40e45f6cfb391cda0a414c8641b6c26735af514
parent dc30e93184466c41c694d2a6d0c6a65b890f0b77
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Mon, 11 Mar 2024 17:44:19 -0700
Add function to link timesheets
Best only do it in one place; it's an error-prone process (plus who
wants to rewrite that every time they want to link a timesheet).
Diffstat:
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/times.c b/times.c
@@ -75,6 +75,18 @@ newtimesheet(void)
{
return calloc(1, sizeof(struct timesheet));
}
+
+struct timesheet *
+inserttimesheet(struct timesheet *ts, struct timesheet *list)
+{
+ if (ts) {
+ ts->prev = list;
+ ts->next = list->next;
+ list->next = ts;
+ }
+ return ts;
+}
+
void
timesheet_set(struct timesheet *ts, enum time_field f, time_t v)
{
@@ -110,10 +122,8 @@ gettimes(struct pagedata *pd, char *hash)
}
if (!times)
times = time;
- else if (oldtime) {
- oldtime->next = time;
- time->prev = oldtime;
- }
+ else if (oldtime)
+ inserttimesheet(time, oldtime);
}
assert(r->psz == 1);
diff --git a/times.h b/times.h
@@ -27,6 +27,7 @@ enum sqlbox_code newrow(struct pagedata *pd, char *hash);
enum sqlbox_code settime(struct pagedata *pd, char *hash, enum time_field f, time_t time);
void freetimesheet(struct timesheet *ts);
struct timesheet *newtimesheet(void);
+struct timesheet *inserttimesheet(struct timesheet *ts, struct timesheet *list);
void timesheet_set(struct timesheet *ts, enum time_field f, time_t v);
struct timesheet *gettimes(struct pagedata *pd, char *hash);
time_t getduration(struct timesheet *ts);