diff options
author | marcinzelent <marcin@zelent.net> | 2017-06-20 14:44:40 +0200 |
---|---|---|
committer | marcinzelent <marcin@zelent.net> | 2017-06-20 14:44:40 +0200 |
commit | 39adeddaf22b9dac3054f47ed0505883b74f7353 (patch) | |
tree | aa3a841b51d26c59cdf6ddfe907173fdfc90d3ad /timetracker.c | |
parent | b70e49e3f6e67255d4417fb39a85988fde0861f6 (diff) |
Changed time formats, optimized printing current activity.
Diffstat (limited to 'timetracker.c')
-rw-r--r-- | timetracker.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/timetracker.c b/timetracker.c index 4b42d2a..0d3d18f 100644 --- a/timetracker.c +++ b/timetracker.c @@ -24,6 +24,7 @@ activity activities_list[100]; int main() { strcpy(current_activity.description,"N/A"); + current_activity.start_time = time(NULL); load_file(); char command; @@ -61,19 +62,20 @@ int main() void print_current_activity() { time_t time_now = time(NULL); + char buf[80]; + + strftime(buf, sizeof(buf), "%H:%M:%S", localtime(¤t_activity.start_time)); printf("==================================================" "==================================================\n" - "Current activity: %s\nStart time: %sDuration: %ld mins.\n" + "Current activity: %s\nStart time: %s\nDuration: %ld mins.\n" "==================================================" "==================================================\n", - current_activity.description, ctime(¤t_activity.start_time), - (time_now - current_activity.start_time)/60); + current_activity.description, buf, (time_now - current_activity.start_time)/60); } void print_activities() { - struct tm ts1, ts2; char buf1[80], buf2[80]; printf("\nPast activities:\n" @@ -81,11 +83,8 @@ void print_activities() "--------------------------------------------------"); for(int i = 0; activities_list[i].start_time; i++) { - ts1 = *localtime(&activities_list[i].start_time); - ts2 = *localtime(&activities_list[i].end_time); - - strftime(buf1, sizeof(buf1), "%a %Y-%m-%d %H:%M:%S %Z", &ts1); - strftime(buf2, sizeof(buf2), "%a %Y-%m-%d %H:%M:%S %Z", &ts2); + strftime(buf1, sizeof(buf1), "%H:%M:%S", localtime(&activities_list[i].start_time)); + strftime(buf2, sizeof(buf2), "%H:%M:%S", localtime(&activities_list[i].end_time)); printf("\nStart time: %s\nEnd time: %s\nActivity: %s\n" "--------------------------------------------------" |