diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit 2bff0783e9ab583e151826f3a19018d59565b795
parent f5301c3970ac054c9cefd8c009e11a4652e38ab6
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Mon, 17 Jan 2022 01:27:57 +0100

feat(caldav): Press 'S' to sync month

Diffstat:
Msrc/diary.c | 28+++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/diary.c b/src/diary.c @@ -585,7 +585,7 @@ int main(int argc, char** argv) { keypad(cal, TRUE); draw_calendar(cal, aside, CONFIG.dir, strlen(CONFIG.dir)); - int ch = 0, conf_ch = -1; + int ch = 0, conf_ch = 0; int pad_pos = 0; int syear = 0, smonth = 0, sday = 0; char ics_filepath[256]; @@ -623,9 +623,6 @@ int main(int argc, char** argv) { char pth[100]; char* ppth = pth; char dstr[16]; - time_t end_time = mktime(&cal_end); - struct tm it = cal_start; - time_t it_time = mktime(&it); edit_cmd(CONFIG.dir, diary_dir_size, &new_date, &pecmd, sizeof ecmd); switch(ch) { @@ -843,9 +840,18 @@ int main(int argc, char** argv) { case 's': caldav_sync(&curs_date, header, cal, pad_pos, CONFIG.dir, diary_dir_size, true); break; - // Sync all entries with CalDAV server; + // Sync entire month with CalDAV server; case 'S': - for( ; it_time <= end_time; it_time = mktime(&it)) { + // end at last day of month + new_date.tm_mon++; + new_date.tm_mday = 0; + time_t end_of_month = mktime(&new_date); + + // start at first day of month + new_date.tm_mday = 1; + time_t new_datetime = mktime(&new_date); + + for( ; new_datetime <= end_of_month; new_datetime = mktime(&new_date)) { if (conf_ch == -1) { // sync error break; @@ -854,12 +860,16 @@ int main(int argc, char** argv) { break; } else if (conf_ch == 'a') { // yes to (a)ll - conf_ch = caldav_sync(&it, header, cal, pad_pos, CONFIG.dir, diary_dir_size, false); + conf_ch = caldav_sync(&new_date, header, cal, pad_pos, CONFIG.dir, diary_dir_size, false); } else { // show confirmation dialogue before overwriting local files - conf_ch = caldav_sync(&it, header, cal, pad_pos, CONFIG.dir, diary_dir_size, true); + conf_ch = caldav_sync(&new_date, header, cal, pad_pos, CONFIG.dir, diary_dir_size, true); } - it.tm_mday++; + // this udpates curs_date (todo: document this better) + go_to(cal, aside, mktime(&new_date), &pad_pos, &curs_date, &cal_start, &cal_end); + update_date(header, &curs_date); + display_entry(CONFIG.dir, diary_dir_size, &curs_date, prev, prev_width); + new_date.tm_mday++; } break; // import from ics file