From e6c0371be1d1c6a208e32f08d78630ab6683efe9 Mon Sep 17 00:00:00 2001 From: "David F. Skoll" Date: Sun, 16 Sep 2007 17:44:33 -0400 Subject: [PATCH] Make calendar times show duration. --- src/calendar.c | 87 +++++++++++++++++++++++++++++++++++++++++++-- src/protos.h | 1 + src/queue.c | 4 +-- tests/test-rem | 9 +++++ tests/test.cmp | 93 +++++++++++++++++++++++++++++++++++++++++++++++-- tests/test3.rem | 29 +++++++++++++++ 6 files changed, 216 insertions(+), 7 deletions(-) create mode 100644 tests/test3.rem diff --git a/src/calendar.c b/src/calendar.c index 9d21df8a..4a5e625e 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -682,7 +682,7 @@ static int DoCalRem(ParsePtr p, int col) return E_NO_MEM; } } else { - if (DBufPuts(&obuf, SimpleTime(tim.ttime)) != OK) { + if (DBufPuts(&obuf, CalendarTime(tim.ttime, tim.duration)) != OK) { DBufFree(&obuf); DBufFree(&pre_buf); return E_NO_MEM; @@ -878,6 +878,89 @@ static void WriteCalDays(void) PutChar('\n'); } +/***************************************************************/ +/* */ +/* CalendarTime */ +/* */ +/* Format the time according to simple time format. */ +/* Answer is returned in a static buffer. */ +/* A trailing space is always added. */ +/* This takes into account duration */ +/* */ +/***************************************************************/ +char * +CalendarTime(int tim, int duration) +{ + static char buf[128]; + int h, min, hh; + int h2, min2, hh2, newtim, days; + char *ampm1; + char *ampm2; + char daybuf[64]; + + buf[0] = 0; + + if (duration == NO_TIME) { + /* No duration... just call into SimpleTime */ + return SimpleTime(tim); + } + if (tim == NO_TIME) { + /* No time... nothing to return */ + return buf; + } + h = tim/60; + min = tim % 60; + if (h == 0) hh=12; + else if (h > 12) hh=h-12; + else hh = h; + + newtim = tim + duration; + + /* How many days in duration? */ + days = newtim / MINUTES_PER_DAY; + newtim = newtim % MINUTES_PER_DAY; + h2 = newtim/60; + min2 = newtim % 60; + if (h2 == 0) hh2=12; + else if (h2 > 12) hh2=h2-12; + else hh2 = h2; + + if (days) { + sprintf(daybuf, "+%d", days); + } else { + daybuf[0] = 0; + } + + if (h >= 12) { + ampm1 = L_PM; + } else { + ampm1 = L_AM; + } + if (h2 >= 12) { + ampm2 = L_PM; + } else { + ampm2 = L_AM; + } + if (!days) { + if (!strcmp(ampm1, ampm2)) { + ampm1 = ""; + } + } + + switch(ScFormat) { + case SC_AMPM: + sprintf(buf, "%d%c%02d%s-%d%c%02d%s%s ", + hh, TimeSep, min, ampm1, hh2, TimeSep, min2, ampm2, daybuf); + break; + + case SC_MIL: + sprintf(buf, "%02d%c%02d-%02d%c%02d%s ", + h, TimeSep, min, h2, TimeSep, min2, daybuf); + break; + } + return buf; +} + /***************************************************************/ /* */ /* SimpleTime */ @@ -903,7 +986,7 @@ char *SimpleTime(int tim) if (h == 0) hh=12; else if (h > 12) hh=h-12; else hh=h; - sprintf(buf, "%2d%c%02d%s ", hh, TimeSep, min, (h>=12) ? L_PM : L_AM); + sprintf(buf, "%d%c%02d%s ", hh, TimeSep, min, (h>=12) ? L_PM : L_AM); } break; diff --git a/src/protos.h b/src/protos.h index b217af29..cdd35f1d 100644 --- a/src/protos.h +++ b/src/protos.h @@ -22,6 +22,7 @@ int CallUserFunc (char *name, int nargs); int DoFset (ParsePtr p); void ProduceCalendar (void); char *SimpleTime (int tim); +char *CalendarTime (int tim, int duration); int DoRem (ParsePtr p); int DoFlush (ParsePtr p); void DoExit (ParsePtr p); diff --git a/src/queue.c b/src/queue.c index dd0929b5..ece3d3b8 100644 --- a/src/queue.c +++ b/src/queue.c @@ -232,9 +232,9 @@ void HandleQueuedReminders(void) strcpy(trig.passthru, q->passthru); RunDisabled = q->RunDisabled; if (Daemon < 0) { - printf("NOTE reminder %s ", + printf("NOTE reminder %s", SimpleTime(q->tt.ttime)); - printf("%s ", SimpleTime(SystemTime(0)/60)); + printf("%s", SimpleTime(SystemTime(0)/60)); if (!*q->tag) { printf("*"); } else { diff --git a/tests/test-rem b/tests/test-rem index 22e79604..dade41a2 100644 --- a/tests/test-rem +++ b/tests/test-rem @@ -27,6 +27,15 @@ echo "" >> ../tests/test.out echo "Test 4" >> ../tests/test.out echo "" >> ../tests/test.out ../src/remind -sa ../tests/test2.rem 1 aug 2007 >> ../tests/test.out +echo "Test 5" >> ../tests/test.out +echo "" >> ../tests/test.out +../src/remind -p -b0 ../tests/test3.rem 1 aug 2007 >> ../tests/test.out +echo "Test 6" >> ../tests/test.out +echo "" >> ../tests/test.out +../src/remind -p -b1 ../tests/test3.rem 1 aug 2007 >> ../tests/test.out +echo "Test 7" >> ../tests/test.out +echo "" >> ../tests/test.out +../src/remind -p -b2 ../tests/test3.rem 1 aug 2007 >> ../tests/test.out cmp -s ../tests/test.out ../tests/test.cmp if [ "$?" = "0" ]; then diff --git a/tests/test.cmp b/tests/test.cmp index 921a5c7d..43e68f59 100644 --- a/tests/test.cmp +++ b/tests/test.cmp @@ -886,7 +886,7 @@ September 30 2007/08/18 * * * * 12 NonOmit-2 2007/08/19 * * * * 17 NonOmit-1 2007/08/19 * * * * 12 NonOmit-2 -2007/08/20 COLOR * * 825 6 7 8 1:45pm Mooo! +2007/08/20 COLOR * * 825 6 7 8 1:45pm Mooo! 2007/08/20 * * * * 18 NonOmit-1 2007/08/20 * * * * 12 NonOmit-2 2007/08/21 PostScript * * 115 (wookie) show @@ -969,7 +969,7 @@ Test 3 2007/08/18 * * * * 12 NonOmit-2 2007/08/19 * * * * 17 NonOmit-1 2007/08/19 * * * * 12 NonOmit-2 -2007/08/20 COLOR * * 825 6 7 8 1:45pm Mooo! +2007/08/20 COLOR * * 825 6 7 8 1:45pm Mooo! 2007/08/20 * * * * 18 NonOmit-1 2007/08/20 * * * * 12 NonOmit-2 2007/08/21 * * * * 19 NonOmit-1 @@ -1050,7 +1050,7 @@ Test 4 2007/08/18 * * * * 12 NonOmit-2 2007/08/19 * * * * 17 NonOmit-1 2007/08/19 * * * * 12 NonOmit-2 -2007/08/20 COLOR * * 825 6 7 8 1:45pm Mooo! +2007/08/20 COLOR * * 825 6 7 8 1:45pm Mooo! 2007/08/20 COLOR * * * 0 0 255 Blue Wednesday is in 2 days' time 2007/08/20 * * * * 18 NonOmit-1 2007/08/20 * * * * 12 NonOmit-2 @@ -1083,3 +1083,90 @@ Test 4 2007/08/30 * * * * 20 NonOmit-2 2007/08/31 * * * * 29 NonOmit-1 2007/08/31 * * * * 21 NonOmit-2 +Test 5 + +# rem2ps begin +August 2007 31 3 0 +Sunday Monday Tuesday Wednesday Thursday Friday Saturday +July 31 +September 30 +2007/08/01 * * * 660 11:00am Wookie +2007/08/01 * * 45 660 11:00-11:45am Lettuce +2007/08/01 * * 105 660 11:00am-12:45pm Apple +2007/08/01 * * 885 660 11:00am-1:45am+1 Green +2007/08/01 * * 1485 660 11:00am-11:45am+1 Yellow +2007/08/01 * * 2205 660 11:00am-11:45pm+1 Purple +2007/08/01 * * 2925 660 11:00am-11:45am+2 Sad +2007/08/01 * * * 720 12:00pm Cookie +2007/08/01 * * 45 720 12:00-12:45pm Cabbage +2007/08/01 * * 165 720 12:00-2:45pm Pear +2007/08/01 * * 885 720 12:00pm-2:45am+1 Blue +2007/08/01 * * 1485 720 12:00pm-12:45pm+1 Orange +2007/08/01 * * 2205 720 12:00pm-12:45am+2 Black +2007/08/01 * * 2925 720 12:00pm-12:45pm+2 Happy +2007/08/01 * * * 780 1:00pm Snookie +2007/08/01 * * 45 780 1:00-1:45pm Tomato +2007/08/01 * * 225 780 1:00-4:45pm Grape +2007/08/01 * * 885 780 1:00pm-3:45am+1 Red +2007/08/01 * * 1485 780 1:00pm-1:45pm+1 Magenta +2007/08/01 * * 2205 780 1:00pm-1:45am+2 Brown +2007/08/01 * * 2925 780 1:00pm-1:45pm+2 Strange +# rem2ps end +Test 6 + +# rem2ps begin +August 2007 31 3 0 +Sunday Monday Tuesday Wednesday Thursday Friday Saturday +July 31 +September 30 +2007/08/01 * * * 660 11:00 Wookie +2007/08/01 * * 45 660 11:00-11:45 Lettuce +2007/08/01 * * 105 660 11:00-12:45 Apple +2007/08/01 * * 885 660 11:00-01:45+1 Green +2007/08/01 * * 1485 660 11:00-11:45+1 Yellow +2007/08/01 * * 2205 660 11:00-23:45+1 Purple +2007/08/01 * * 2925 660 11:00-11:45+2 Sad +2007/08/01 * * * 720 12:00 Cookie +2007/08/01 * * 45 720 12:00-12:45 Cabbage +2007/08/01 * * 165 720 12:00-14:45 Pear +2007/08/01 * * 885 720 12:00-02:45+1 Blue +2007/08/01 * * 1485 720 12:00-12:45+1 Orange +2007/08/01 * * 2205 720 12:00-00:45+2 Black +2007/08/01 * * 2925 720 12:00-12:45+2 Happy +2007/08/01 * * * 780 13:00 Snookie +2007/08/01 * * 45 780 13:00-13:45 Tomato +2007/08/01 * * 225 780 13:00-16:45 Grape +2007/08/01 * * 885 780 13:00-03:45+1 Red +2007/08/01 * * 1485 780 13:00-13:45+1 Magenta +2007/08/01 * * 2205 780 13:00-01:45+2 Brown +2007/08/01 * * 2925 780 13:00-13:45+2 Strange +# rem2ps end +Test 7 + +# rem2ps begin +August 2007 31 3 0 +Sunday Monday Tuesday Wednesday Thursday Friday Saturday +July 31 +September 30 +2007/08/01 * * * 660 Wookie +2007/08/01 * * 45 660 Lettuce +2007/08/01 * * 105 660 Apple +2007/08/01 * * 885 660 Green +2007/08/01 * * 1485 660 Yellow +2007/08/01 * * 2205 660 Purple +2007/08/01 * * 2925 660 Sad +2007/08/01 * * * 720 Cookie +2007/08/01 * * 45 720 Cabbage +2007/08/01 * * 165 720 Pear +2007/08/01 * * 885 720 Blue +2007/08/01 * * 1485 720 Orange +2007/08/01 * * 2205 720 Black +2007/08/01 * * 2925 720 Happy +2007/08/01 * * * 780 Snookie +2007/08/01 * * 45 780 Tomato +2007/08/01 * * 225 780 Grape +2007/08/01 * * 885 780 Red +2007/08/01 * * 1485 780 Magenta +2007/08/01 * * 2205 780 Brown +2007/08/01 * * 2925 780 Strange +# rem2ps end diff --git a/tests/test3.rem b/tests/test3.rem new file mode 100644 index 00000000..84650773 --- /dev/null +++ b/tests/test3.rem @@ -0,0 +1,29 @@ +REM 1 AT 11:00 MSG Wookie +REM 1 AT 12:00 MSG Cookie +REM 1 AT 13:00 MSG Snookie + +REM 1 AT 11:00 DURATION 0:45 MSG Lettuce +REM 1 AT 12:00 DURATION 0:45 MSG Cabbage +REM 1 AT 13:00 DURATION 0:45 MSG Tomato + +REM 1 AT 11:00 DURATION 1:45 MSG Apple +REM 1 AT 12:00 DURATION 2:45 MSG Pear +REM 1 AT 13:00 DURATION 3:45 MSG Grape + +REM 1 AT 11:00 DURATION 14:45 MSG Green +REM 1 AT 12:00 DURATION 14:45 MSG Blue +REM 1 AT 13:00 DURATION 14:45 MSG Red + +REM 1 AT 11:00 DURATION 24:45 MSG Yellow +REM 1 AT 12:00 DURATION 24:45 MSG Orange +REM 1 AT 13:00 DURATION 24:45 MSG Magenta + +REM 1 AT 11:00 DURATION 36:45 MSG Purple +REM 1 AT 12:00 DURATION 36:45 MSG Black +REM 1 AT 13:00 DURATION 36:45 MSG Brown + +REM 1 AT 11:00 DURATION 48:45 MSG Sad +REM 1 AT 12:00 DURATION 48:45 MSG Happy +REM 1 AT 13:00 DURATION 48:45 MSG Strange + +