dedicated functions for calculating hours, minutes, seconds

This commit is contained in:
randomuser 2021-06-11 00:58:16 -05:00
parent b2ede86e69
commit f8d95fd733
2 changed files with 19 additions and 2 deletions

View File

@ -31,8 +31,9 @@ int timerissettings(struct timer *t) {
char *timerdisp(struct timer *t) {
char *str = malloc(20);
if(s.f) snprintf(str, 20, "%02i:%02i:%02i",
((t->s / 60) / 60), (t->s / 60) % 60, t->s % 60);
else snprintf(str, 20, "%02i:%02i", t->s / 60, t->s % 60);
hours(t->s), minutes(t->s), seconds(t->s));
/* TODO: give minute(...) and minutes(...) better names */
else snprintf(str, 20, "%02i:%02i", minute(t->s), seconds(t->s));
return str;
}

View File

@ -39,6 +39,22 @@ int timerzero(struct timer *t) {
return 0;
}
int seconds(int t) {
return t % 60;
}
int minutes(int t) {
return (t / 60) % 60;
}
int minute(int t) {
return t / 60;
}
int hours(int t) {
return (t / 60) / 60;
}
struct timer *timerinit(void) {
struct timer *t = malloc(sizeof *t);
t->s = 0;