From 6915ca9ad6c5fbe9a327278e44c472d139a16864 Mon Sep 17 00:00:00 2001 From: Nicholas Dietz Date: Tue, 14 Jan 2025 14:27:43 -0600 Subject: [PATCH] Add date stamp every time midnight rolls around Add date stamp every time a new history entry appears for a new day. --- src/history.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/history.c b/src/history.c index 5ca722a..74bd692 100644 --- a/src/history.c +++ b/src/history.c @@ -186,6 +186,8 @@ void load_history_from(const char *path){ static void export_session_into_text(FILE *f, const struct history_session *session) { char time_buff[512]; + char date_buff[512]; + char prev_date_buff[512]; struct tm *tm = localtime(&session->timestamp); strftime(time_buff, 512, "%F | %H:%M", tm); @@ -196,8 +198,14 @@ static void export_session_into_text(FILE *f, const struct history_session *sess struct history_entry *entry = &session->entries[i]; tm = localtime_r(&entry->timestamp, tm); - strftime(time_buff, 512, "%T", tm); + strftime(time_buff, sizeof(time_buff), "%T", tm); + strftime(date_buff, sizeof(date_buff), "%F", tm); + if (strcmp(date_buff, prev_date_buff) != 0) { + fprintf(f, " -[ %s ]- ", date_buff); + strncpy(prev_date_buff, date_buff, sizeof(prev_date_buff)); + } + fprintf(f, "\n(%s) - ", time_buff); for(size_t j=0; jtokens_count; j++){ @@ -253,4 +261,4 @@ void erase_all_history(void){ past_sessions.sessions = NULL; save_current_history(default_history_file); -} \ No newline at end of file +}