blob: 7ea5f2e8f458cdf7a9d741fb8af7439bc35a8a71 (
plain)
1 #include "ctime.h"
2
3 void ctime_t_new(ctime_t* t) {
4 t->sec = 0;
5 t->min = 0;
6 t->hour = 0;
7 t->day = 0;
8 t->month = 0;
9 t->year = 0;
10 }
11
12 int ctime_add_sec(ctime_t* t) {
13 t->sec++;
14
15 if(t->sec > 59) {
16 // Increment minute
17 t->min++;
18 // TODO: This doesn't work when duration > 1. Need better logic here.
19 t->sec = 0;
20 }
21
22 if(t->min == 60) {
23 t->hour++;
24 t->min = 0;
25 } else {
26 // Return early since we won't increment anything before 60
27 return 0;
28 }
29
30 if(t->hour == 24) {
31 t->day++;
32 t->hour = 0;
33 } else {
34 // Return early since we won't increment anything before 24
35 return 0;
36 }
37
38 if(t->day == 366) {
39 t->year++;
40 t->day = 0;
41 } else {
42 // Return early since we won't increment anything before 24
43 return 0;
44 }
45
46 return 1;
47 }
|