Added day switching.

This commit is contained in:
2026-02-21 00:01:53 -08:00
parent 78e4fcff29
commit c7b75393ee
2 changed files with 44 additions and 4 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@ main
main.dSYM
third_party
sourcecodepro.ttf
.DS_Store

47
main.c
View File

@@ -177,10 +177,8 @@ void switch_activity(activity *activities, U32 *current_activity, activity_type
int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
activity activities[100];
memset(activities, 0, sizeof(activities));
U32 current_activity = 0;
Activity_Stat activities_stats[activity_type_COUNT];
@@ -306,7 +304,7 @@ int main(int argc, char *argv[])
// Initialize to default activity at the start.
// NOTE: We can potentially make the default a non-state, so the users
// choos themselves.
// choose themselves.
activities[current_activity].type = other;
activities[current_activity].color = RED;
activities[current_activity].began = now();
@@ -320,6 +318,47 @@ int main(int argc, char *argv[])
while(!WindowShouldClose()) {
U64 now_s = now();
// NOTE: WARNING: TODO: Temporary solution; to be cleaned up.
if(now_s >= upper_bound_s) {
U64 secs = now();
t = localtime((time_t *)(&secs));
t->tm_hour = 0;
t->tm_min = 0;
t->tm_sec = 0;
time_t ts = mktime(t);
if(ts == (time_t)-1) {
fprintf(stderr, "mktime failed.\n");
return 1;
}
lower_bound_s = (U64)ts;
upper_bound_s = lower_bound_s + 86400;
fclose(f);
strftime(date_buffer, sizeof(date_buffer), "%Y_%m_%d", t);
snprintf(file_buffer, sizeof(file_buffer), "%s/%s", dir_buffer,
date_buffer);
f = fopen(file_buffer, "w+");
if(!f) {
fprintf(stderr, "Failed to create file: %s\n", file_buffer);
return 1;
}
activity_type type = activities[current_activity].type;
memset(activities, 0, sizeof(activities));
memset(activities_stats, 0, sizeof(activities_stats));
current_activity = 0;
activities[current_activity].type = type;
activities[current_activity].color =
activity_type_color_representation[type];
activities[current_activity].began = now();
}
window_w = GetScreenWidth();
window_h = GetScreenHeight();