From 795301860f3a2a36e66396f2c57552f16d5c170b Mon Sep 17 00:00:00 2001 From: louie Date: Sun, 2 Jul 2023 17:16:59 -0700 Subject: Use 'struct tm' for date in entries --- src/db/sqlite3/db.c | 2 +- src/entry.c | 8 ++++++++ src/entry.h | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/db/sqlite3/db.c b/src/db/sqlite3/db.c index dd46071..36981d4 100644 --- a/src/db/sqlite3/db.c +++ b/src/db/sqlite3/db.c @@ -52,7 +52,7 @@ int create_tables(const char *path) { "CREATE TABLE IF NOT EXISTS 'Entry' (" "'ID' int NOT NULL PRIMARY KEY, " "'Group_ID' int NOT NULL, " // FIXME might want foreign key constraint - // TODO add due_date here once it's figure out + "'Due_date' date DEFAULT NULL, " "'Alt_due_date' varchar(%d) DEFAULT NULL, " "'Title' varchar(%d) NOT NULL, " "'Color' varchar(%d) DEFAULT NULL, " diff --git a/src/entry.c b/src/entry.c index 2d5f7d0..f996a00 100644 --- a/src/entry.c +++ b/src/entry.c @@ -3,6 +3,10 @@ #include "entry.h" // getters +struct tm entry_get_due_date(Entry *e) { + return e->due_date; +} + char *entry_get_alt_due_date(Entry *e) { return e->alt_due_date; } @@ -29,6 +33,10 @@ char *entry_get_url(Entry *e) { // setters +void entry_set_due_date(Entry *e, struct tm due_date) { + e->due_date = due_date; +} + void entry_set_alt_due_date(Entry *e, char *alt_due_date) { strcpy(e->alt_due_date, alt_due_date); } diff --git a/src/entry.h b/src/entry.h index a2f637e..298b9b4 100644 --- a/src/entry.h +++ b/src/entry.h @@ -2,12 +2,13 @@ #define ENTRY_H #include +#include #include "../config.h" // a group/category for entries to be put in typedef struct { - //TODO due_date + struct tm due_date; char alt_due_date[BUF_LEN]; char title[BUF_LEN]; char color[BUF_LEN]; // TODO consider making an enum @@ -17,6 +18,7 @@ typedef struct { } Entry; // getters +struct tm entry_get_due_date(Entry *e); char *entry_get_alt_due_date(Entry *e); char *entry_get_title(Entry *e); char *entry_get_color(Entry *e); @@ -25,6 +27,7 @@ bool entry_get_done(Entry *e); char *entry_get_url(Entry *e); // setters +void entry_set_due_date(Entry *e, struct tm due_date); void entry_set_alt_due_date(Entry *e, char *alt_due_date); void entry_set_title(Entry *e, char *title); void entry_set_color(Entry *e, char *color); -- cgit