Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add date stamp every time midnight rolls around #103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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; j<entry->tokens_count; j++){
Expand Down Expand Up @@ -253,4 +261,4 @@ void erase_all_history(void){
past_sessions.sessions = NULL;

save_current_history(default_history_file);
}
}