aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--date.c31
-rw-r--r--date.h2
-rw-r--r--main.c9
3 files changed, 40 insertions, 2 deletions
diff --git a/date.c b/date.c
index 4cab1d2..abd09df 100644
--- a/date.c
+++ b/date.c
@@ -20,6 +20,14 @@ bool smaller(Date a, Date b) {
((a.year == b.year) && (a.month == b.month) && (a.day <= b.day)));
}
+bool strictly_smaller(Date a, Date b) {
+ if (zero(b)) return true;
+ if (zero(a)) return false;
+ return ((a.year < b.year) ||
+ ((a.year == b.year) && (a.month < b.month)) ||
+ ((a.year == b.year) && (a.month == b.month) && (a.day < b.day)));
+}
+
bool eql(Date a, Date b) {
return (a.day == b.day) &&
(a.month == b.month) &&
@@ -53,6 +61,29 @@ Date today() {
return ret;
}
+Date tomorrow(Date td) {
+ Date tm = { td.day+1, td.month, td.year };
+ if (tm.month == FEB && tm.day > 28) {
+ if (tm.year % 4 == 0 && tm.day > 29) {
+ tm.day -= 29; tm.month++;
+ } else {
+ tm.day -= 28; tm.month++;
+ }
+ } else if (tm.month == JAN || tm.month == MAR || tm.month == MAY || tm.month == JUL ||
+ tm.month == AUG || tm.month == OCT || tm.month == DEC) {
+ if (tm.day > 31 && tm.month == DEC) {
+ tm.day -= 31; tm.month = 1;
+ } else if (tm.day > 31) {
+ tm.day -= 31; tm.month++;
+ }
+ } else if (tm.month == APR || tm.month == JUN || tm.month == SEP || tm.month == NOV) {
+ if (tm.day > 30) {
+ tm.day -= 30; tm.month++;
+ }
+ }
+ return tm;
+}
+
Date nextweek(Date td) {
Date nw = { td.day+7, td.month, td.year };
if (nw.month == FEB && nw.day > 28) {
diff --git a/date.h b/date.h
index 649b90f..b9c4e3c 100644
--- a/date.h
+++ b/date.h
@@ -12,6 +12,7 @@ typedef struct Date {
Date extract_date(char *str);
bool smaller(Date a, Date b);
+bool strictly_smaller(Date a, Date b);
bool eql(Date a, Date b);
bool zero(Date a);
@@ -19,6 +20,7 @@ void print_date(Date date);
char *print_date_to_string(Date date);
Date today();
+Date tomorrow(Date td);
Date nextweek(Date td);
#define __DATE_H__
diff --git a/main.c b/main.c
index 7b111c8..a5c300a 100644
--- a/main.c
+++ b/main.c
@@ -73,15 +73,20 @@ int main(int argc, char **argv) {
// format nicely
char *e;
Date td = today();
+ Date tm = tomorrow(td);
Date nw = nextweek(td);
- Date last_date = (struct Date){ -1, -1, -1 };//agenda[0].date;
+ Date last_date = (struct Date){ -1, -1, -1 };
for (int i = 0; i < idx; i++) {
if (!eql(agenda[i].date, last_date)) {
last_date = agenda[i].date;
if (!zero(last_date)) {
e = print_date_to_string(last_date);
- if (smaller(last_date, td))
+ if (strictly_smaller(last_date, td))
printf("\n%s [OUTATIME]:\n", e);
+ else if (eql(last_date, td))
+ printf("\n%s [TODAY]:\n", e);
+ else if (eql(last_date, tm))
+ printf("\n%s [TOMORROW]:\n", e);
else if (smaller(last_date, nw))
printf("\n%s:\n", e);
free(e);