From f9b704e423eb4110648a6468e38bbffe2479e9ff Mon Sep 17 00:00:00 2001 From: xavi Date: Sat, 5 Oct 2024 21:51:43 -0700 Subject: [PATCH] Modified due_date functions --- src/dodo.c | 80 ++++++++++++++++++++++++++++++++++++++---------------- src/dodo.h | 5 +++- tags | 19 +++++++++---- 3 files changed, 75 insertions(+), 29 deletions(-) diff --git a/src/dodo.c b/src/dodo.c index 109bf81..e3a7899 100644 --- a/src/dodo.c +++ b/src/dodo.c @@ -31,61 +31,97 @@ int view_all(sqlite3 *db){ return rc; } -int get_today_or_tom(struct tm *d, time_t rawtime, int day_offset){ +int get_today(date *d){ + struct tm *local; + time_t rawtime; - rawtime += SECS_IN_DAY * day_offset; time(&rawtime); - d = localtime(&rawtime); + local = localtime(&rawtime); + + d->year = local->tm_year + 1900; + d->month = local->tm_mon + 1; + d->day = local->tm_mday; + d->dow = local->tm_wday; return 0; } -int get_day_of_week(struct tm *d, time_t rawtime, int target_day_of_week){ +int get_day_of_week(date *d, int target_day_of_week){ + struct tm *local; + time_t rawtime; int days_to_add = 0; - time(&rawtime); - d = localtime(&rawtime); - days_to_add = ( target_day_of_week - d->tm_wday + 7 ) % 7; + time(&rawtime); + local = localtime(&rawtime); + + days_to_add = ( target_day_of_week - local->tm_wday + 7 ) % 7; if ( days_to_add == 0 ){ days_to_add = 7; } - //d->tm_mday += days_to_add; + local->tm_mday += days_to_add; - //mktime(d); + mktime(local); + + d->year = local->tm_year + 1900; + d->month = local->tm_mon + 1; + d->day = local->tm_mday; + d->dow = local->tm_wday; return 0; } int get_due_date(filtered_tasks *task, char* passed_date){ - time_t rawtime; - int day_offset = 0; int day_of_week = 0; // Sunday = 0 Monday = 1 .. Saterday = 6 - struct tm *d; + date *d = malloc(sizeof(date)); if ( x_strcmp(passed_date, "today") == 0 ){ - day_offset = 0; - get_today_or_tom(d, rawtime, day_offset); + get_today(d); } else if ( x_strcmp(passed_date, "tomorrow") == 0 ) { - day_offset = 1; - get_today_or_tom(d, rawtime, day_offset); + get_today(d); + get_day_of_week(d, d->dow + 1); + } + else if ( x_strcmp(passed_date, "sun") == 0 ){ + day_of_week = 0; + get_day_of_week(d, day_of_week); + } + else if ( x_strcmp(passed_date, "mon") == 0 ){ + day_of_week = 1; + get_day_of_week(d, day_of_week); + } + else if ( x_strcmp(passed_date, "tues") == 0 ){ + day_of_week = 2; + get_day_of_week(d, day_of_week); } else if ( x_strcmp(passed_date, "wed") == 0 ){ - day_of_week = 3; - get_day_of_week(d, rawtime, day_of_week); + day_of_week = 3; + get_day_of_week(d, day_of_week); + } + else if ( x_strcmp(passed_date, "thurs") == 0 ){ + day_of_week = 4; + get_day_of_week(d, day_of_week); + } + else if ( x_strcmp(passed_date, "fri") == 0 ){ + day_of_week = 5; + get_day_of_week(d, day_of_week); + } + else if ( x_strcmp(passed_date, "sat") == 0 ){ + day_of_week = 6; + get_day_of_week(d, day_of_week); } else{ task->due_date = passed_date; + return 0; } - task->due_date = malloc(100 * sizeof(char)); - printf("%04d-%02d-%02d", d->tm_year + 1900, d->tm_mon + 1, d->tm_mday); + task->due_date = malloc(ARG_MAX * sizeof(char)); + snprintf(task->due_date, ARG_MAX, "%04d-%02d-%02d", d->year, d->month, d->day); - + return 0; } void init_filtered_tasks(filtered_tasks* task){ @@ -437,7 +473,6 @@ int parse_args(int argc, char** argv, filtered_tasks* task){ if ( argc > 3 ){ if ( x_strcmp(argv[1], "update") ){ get_due_date(task, argv[3]); - task->due_date = argv[3]; return 0; } else{ @@ -447,7 +482,6 @@ int parse_args(int argc, char** argv, filtered_tasks* task){ if ( argc > 4 ){ get_due_date(task, argv[4]); - task->due_date = argv[4]; } if ( argc > 5 ){ diff --git a/src/dodo.h b/src/dodo.h index 958325a..0ea9ba1 100644 --- a/src/dodo.h +++ b/src/dodo.h @@ -23,7 +23,7 @@ #define TODAY_COL_START -1 #define BACKLOG_COL_START (FIXED_COLUMN_WIDTH + 1) #define BLOCKED_COL_START ( 2 * (FIXED_COLUMN_WIDTH + 1) ) -#define SECS_IN_DAY 86400 +#define SECS_IN_DAY 864000 // TODO maybe I should make another module that is strictly @@ -31,6 +31,7 @@ typedef struct{ int year; int month; int day; + int dow; // day of the week }date; // Filters for sql selection @@ -55,6 +56,8 @@ void init_filtered_tasks(filtered_tasks* task); // Due Date stuff int init_date(struct tm*, int day_offset); int get_due_date(filtered_tasks *task, char* due_date); +int get_today(date *d); +int get_day_of_week(date *d, int target_day_of_week); // sql generators TODO: might be able to boil this down to 1 func int prepare_sql_update_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* task); diff --git a/tags b/tags index ccebff9..fee4157 100644 --- a/tags +++ b/tags @@ -929,6 +929,7 @@ SAVEPOINT_ROLLBACK src/sqlite3/src/sqlite3.c /^#define SAVEPOINT_ROLLBACK /;" d SCHEMA_ENC src/sqlite3/src/sqlite3.c /^#define SCHEMA_ENC(/;" d file: SCHEMA_ROOT src/sqlite3/src/sqlite3.c /^#define SCHEMA_ROOT /;" d file: SCHEMA_TABLE src/sqlite3/src/sqlite3.c /^#define SCHEMA_TABLE(/;" d file: +SECS_IN_DAY src/dodo.h /^#define SECS_IN_DAY /;" d SET_FULLSYNC src/sqlite3/src/sqlite3.c /^# define SET_FULLSYNC(/;" d file: SFUNCTION src/sqlite3/src/sqlite3.c /^#define SFUNCTION(/;" d file: SF_Aggregate src/sqlite3/src/sqlite3.c /^#define SF_Aggregate /;" d file: @@ -3091,9 +3092,11 @@ day src/dodo.h /^ int day;$/;" m struct:__anon569311380108 typeref:typename:int day src/sqlite3/src/sqlite3.c /^ sqlite3_int64 day;$/;" l function:parseModifier typeref:typename:sqlite3_int64 file: day_min src/sqlite3/src/sqlite3.c /^ int day_ms, day_min; \/* milliseconds, minutes into the day *\/$/;" l function:computeHMS typeref:typename:int file: day_ms src/sqlite3/src/sqlite3.c /^ int day_ms, day_min; \/* milliseconds, minutes into the day *\/$/;" l function:computeHMS typeref:typename:int file: +day_of_week src/dodo.c /^ int day_of_week = 0; \/\/ Sunday = 0 Monday = 1 .. Saterday = 6$/;" l function:get_due_date typeref:typename:int file: daysAfterJan01 src/sqlite3/src/sqlite3.c /^static int daysAfterJan01(DateTime *pDate){$/;" f typeref:typename:int file: daysAfterMonday src/sqlite3/src/sqlite3.c /^static int daysAfterMonday(DateTime *pDate){$/;" f typeref:typename:int file: daysAfterSunday src/sqlite3/src/sqlite3.c /^static int daysAfterSunday(DateTime *pDate){$/;" f typeref:typename:int file: +days_to_add src/dodo.c /^ int days_to_add = 0;$/;" l function:get_day_of_week typeref:typename:int file: db src/main.c /^ sqlite3 *db;$/;" l function:main typeref:typename:sqlite3 * file: db src/sqlite3/src/sqlite3.c /^ sqlite3 *db = p->db;$/;" l function:sqlite3ProgressCheck typeref:typename:sqlite3 * file: db src/sqlite3/src/sqlite3.c /^ sqlite3 *db = pParse->db;$/;" l function:sqlite3ErrorMsg typeref:typename:sqlite3 * file: @@ -3158,6 +3161,7 @@ done src/sqlite3/src/sqlite3.c /^ etByte done; \/* Loop terminati done src/sqlite3/src/sqlite3.c /^ int done; \/* Set to true when thread finishes *\/$/;" m struct:SQLiteThread typeref:typename:int file: double src/sqlite3/src/sqlite3.c /^# define double /;" d file: double src/sqlite3/src/sqlite3.h /^# define double /;" d +dow src/dodo.h /^ int dow; \/\/ day of the week$/;" m struct:__anon569311380108 typeref:typename:int due_date src/dodo.h /^ char *due_date;$/;" m struct:__anon569311380208 typeref:typename:char * e src/sqlite3/src/sqlite3.c /^ LogEst e;$/;" l function:sqlite3LogEstFromDouble typeref:typename:LogEst file: e src/sqlite3/src/sqlite3.c /^ int e = 0; \/* exponent *\/$/;" l function:sqlite3AtoF typeref:typename:int file: @@ -3301,10 +3305,14 @@ getTextArg src/sqlite3/src/sqlite3.c /^static char *getTextArg(PrintfArguments * getVarint src/sqlite3/src/sqlite3.c /^#define getVarint /;" d file: getVarint32 src/sqlite3/src/sqlite3.c /^#define getVarint32(/;" d file: getVarint32NR src/sqlite3/src/sqlite3.c /^#define getVarint32NR(/;" d file: -get_due_date src/dodo.c /^int get_due_date(filtered_tasks *task, char* due_date){$/;" f typeref:typename:int +get_day_of_week src/dodo.c /^int get_day_of_week(date *d, int target_day_of_week){$/;" f typeref:typename:int +get_day_of_week src/dodo.h /^int get_day_of_week(date *d, int target_day_of_week);$/;" p typeref:typename:int +get_due_date src/dodo.c /^int get_due_date(filtered_tasks *task, char* passed_date){$/;" f typeref:typename:int get_due_date src/dodo.h /^int get_due_date(filtered_tasks *task, char* due_date);$/;" p typeref:typename:int get_num_rows src/dodo.c /^int get_num_rows(sqlite3 *db, char* table, char* status){$/;" f typeref:typename:int get_num_rows src/dodo.h /^int get_num_rows(sqlite3 *db, char* table, char* status);$/;" p typeref:typename:int +get_today src/dodo.c /^int get_today(date *d){$/;" f typeref:typename:int +get_today src/dodo.h /^int get_today(date *d);$/;" p typeref:typename:int h src/sqlite3/src/sqlite3.c /^ int h = x.h;$/;" l function:strftimeFunc typeref:typename:int file: h src/sqlite3/src/sqlite3.c /^ int Y,M,D,h,m,x;$/;" l function:parseModifier typeref:typename:int file: h src/sqlite3/src/sqlite3.c /^ int h, m, s;$/;" l function:parseHhMmSs typeref:typename:int file: @@ -3526,8 +3534,7 @@ incr src/sqlite3/src/sqlite3.c /^ int incr;$/;" l function:sqlite3AtoF typeref: incr src/sqlite3/src/sqlite3.c /^ int incr;$/;" l function:sqlite3Atoi64 typeref:typename:int file: infop src/sqlite3/src/sqlite3.c /^ const et_info *infop; \/* Pointer to the appropriate info structure *\/$/;" l function:sqlite3_str_vappendf typeref:typename:const et_info * file: init src/sqlite3/src/sqlite3.c /^ } init;$/;" m struct:sqlite3 typeref:struct:sqlite3::sqlite3InitInfo file: -init_date src/dodo.c /^int init_date(date *d){$/;" f typeref:typename:int -init_date src/dodo.h /^int init_date(date* date);$/;" p typeref:typename:int +init_date src/dodo.h /^int init_date(struct tm*, int day_offset);$/;" p typeref:typename:int init_filtered_tasks src/dodo.c /^void init_filtered_tasks(filtered_tasks* task){$/;" f typeref:typename:void init_filtered_tasks src/dodo.h /^void init_filtered_tasks(filtered_tasks* task);$/;" p typeref:typename:void install Makefile /^install:$/;" t @@ -3595,7 +3602,8 @@ length src/sqlite3/src/sqlite3.c /^ int length; \/* Length of th likely src/sqlite3/src/sqlite3.c /^#define likely(/;" d file: list src/sqlite3/src/sqlite3.c /^ } list;$/;" m union:Mem3Block::__anon176c6ffd3e0a typeref:struct:Mem3Block::__anon176c6ffd3e0a::__anon176c6ffd4008 file: lo src/sqlite3/src/sqlite3.c /^ unsigned int lo, hi;$/;" l function:sqlite3Hwtime typeref:typename:unsigned int file: -local src/dodo.c /^ struct tm *local = localtime(&rawtime);$/;" l function:init_date typeref:struct:tm * file: +local src/dodo.c /^ struct tm *local;$/;" l function:get_day_of_week typeref:struct:tm * file: +local src/dodo.c /^ struct tm *local;$/;" l function:get_today typeref:struct:tm * file: local_ioerr src/sqlite3/src/sqlite3.c /^static void local_ioerr(){$/;" f typeref:typename:void file: localtime src/sqlite3/src/sqlite3.c /^struct tm *__cdecl localtime(const time_t *);$/;" p typeref:struct:tm * __cdecl file: lockMask src/sqlite3/src/sqlite3.c /^ yDbMask lockMask; \/* Subset of btreeMask that requires a lock *\/$/;" m struct:Vdbe typeref:typename:yDbMask file: @@ -4527,7 +4535,8 @@ rScore src/sqlite3/src/sqlite3.h /^ sqlite3_rtree_dbl rScore; \/* OUT: rXform src/sqlite3/src/sqlite3.c /^ float rXform; \/* Constant used for this transform *\/$/;" m struct:__anon176c6ffd3c08 typeref:typename:float file: randomFill src/sqlite3/src/sqlite3.c /^static void randomFill(char *pBuf, int nByte){$/;" f typeref:typename:void file: rawS src/sqlite3/src/sqlite3.c /^ unsigned rawS : 1; \/* Raw numeric value stored in s *\/$/;" m struct:DateTime typeref:typename:unsigned:1 file: -rawtime src/dodo.c /^ time_t rawtime;$/;" l function:init_date typeref:typename:time_t file: +rawtime src/dodo.c /^ time_t rawtime;$/;" l function:get_day_of_week typeref:typename:time_t file: +rawtime src/dodo.c /^ time_t rawtime;$/;" l function:get_today typeref:typename:time_t file: rc src/dodo.c /^ int rc = 0;$/;" l function:add_new_task typeref:typename:int file: rc src/dodo.c /^ int rc = 0;$/;" l function:bind_sql_delete_stmt typeref:typename:int file: rc src/dodo.c /^ int rc = 0;$/;" l function:bind_sql_insert_stmt typeref:typename:int file: