diff --git a/progs/timer.c b/progs/timer.c index 78bf949..3ad9967 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -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; } diff --git a/progs/timerlib.c b/progs/timerlib.c index 6d02d66..3e8e39c 100644 --- a/progs/timerlib.c +++ b/progs/timerlib.c @@ -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;