dedicated functions for calculating hours, minutes, seconds
This commit is contained in:
parent
b2ede86e69
commit
f8d95fd733
|
@ -31,8 +31,9 @@ int timerissettings(struct timer *t) {
|
||||||
char *timerdisp(struct timer *t) {
|
char *timerdisp(struct timer *t) {
|
||||||
char *str = malloc(20);
|
char *str = malloc(20);
|
||||||
if(s.f) snprintf(str, 20, "%02i:%02i:%02i",
|
if(s.f) snprintf(str, 20, "%02i:%02i:%02i",
|
||||||
((t->s / 60) / 60), (t->s / 60) % 60, t->s % 60);
|
hours(t->s), minutes(t->s), seconds(t->s));
|
||||||
else snprintf(str, 20, "%02i:%02i", t->s / 60, t->s % 60);
|
/* TODO: give minute(...) and minutes(...) better names */
|
||||||
|
else snprintf(str, 20, "%02i:%02i", minute(t->s), seconds(t->s));
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,22 @@ int timerzero(struct timer *t) {
|
||||||
return 0;
|
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 *timerinit(void) {
|
||||||
struct timer *t = malloc(sizeof *t);
|
struct timer *t = malloc(sizeof *t);
|
||||||
t->s = 0;
|
t->s = 0;
|
||||||
|
|
Loading…
Reference in New Issue