Hi,

I missed that struct tm uses 0-indexed months, and birthday uses
1-indexed ones. This revised patch gets that right.

[how would you feel about an NMU for this?]

Regards,

Matthew



-- 
 The Wellcome Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE. 
>From 249403c52334e8e2ae8de106ab1e805e10784fdd Mon Sep 17 00:00:00 2001
From: Matthew Vernon <m...@sanger.ac.uk>
Date: Wed, 20 Mar 2019 15:37:46 +0000
Subject: [PATCH] add -L option to output day and month name in list view

---
 bdengine.c       | 16 ++++++++++++++++
 birthday.c       |  5 ++++-
 birthday.h       |  1 +
 birthday.man     |  4 ++++
 debian/changelog |  7 +++++++
 5 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/bdengine.c b/bdengine.c
index 7985843..545405e 100644
--- a/bdengine.c
+++ b/bdengine.c
@@ -63,6 +63,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 
 #ifdef UNIX
 #include <sys/types.h>
@@ -83,6 +84,7 @@ struct event *dir_include(char *dir, char *parm, const struct date *today);
 int iDWarn   = DEF_WARN;
 int iMaxWarn = MAX_WARN;
 int iMinWarn = MIN_WARN;
+int iPrintDate = 0;
 
 const unsigned MLENDAT[]={31,-1,31,30,31,30,31,31,30,31,30,31};
 
@@ -252,6 +254,7 @@ void liststrings(struct event *evl, prnfunc outf, const struct date *today) {
    int i,j;
    char *buf, *tmp;
    int size;
+   struct tm *tmptime;
    
    for (i = 0; evl[i].text != NULL; i++) {
       buf = xmalloc(128);
@@ -266,6 +269,19 @@ void liststrings(struct event *evl, prnfunc outf, const struct date *today) {
             append(buf, " ");
             tmp = tdelta(&(evl[i].date), today);
             append(buf, tmp);
+	    /* only print date if it's not today or tomorrow */
+	    if ((iPrintDate > 0) && (delta(&evl[i].date, today) > 1)) {
+	      tmptime = (struct tm *)xmalloc(sizeof *tmptime);
+	      tmptime = (struct tm *)memset(tmptime,0,(sizeof *tmptime));
+	      tmptime->tm_mday = evl[i].date.day;
+	      /*struct tm tm_mon is [0-11], our month is [1-12]*/ 
+	      tmptime->tm_mon = evl[i].date.month - 1;
+	      if (strftime(tmp,128," (%e %B)",tmptime))
+		append(buf, tmp);
+	      else
+		fatal("strftime failed\n");
+	      free(tmptime);
+	    }
             free(tmp);
          }
       } else {
diff --git a/birthday.c b/birthday.c
index 59daf07..717bdc7 100644
--- a/birthday.c
+++ b/birthday.c
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
   func = F_WARN;
   settoday( &today );
 
-  while ((i = getopt (argc, argv, "wcf:W:M:m:l:p:d:i:T:")) != -1)
+  while ((i = getopt (argc, argv, "wcLf:W:M:m:l:p:d:i:T:")) != -1)
     switch (i)
       {
       case 'w':
@@ -85,6 +85,9 @@ int main(int argc, char *argv[])
       case 'l':
 	iCLines=atoi(optarg);
 	break;
+      case 'L':
+	iPrintDate = 1;
+	break;
       case 'p':
 	iCWeeks=atoi(optarg);
 	break;
diff --git a/birthday.h b/birthday.h
index 6df7e70..0106701 100644
--- a/birthday.h
+++ b/birthday.h
@@ -114,6 +114,7 @@ extern struct date today;
 extern int iDWarn;
 extern int iMaxWarn;
 extern int iMinWarn;
+extern int iPrintDate;
 
 extern int iCLines;
 extern int iCWidth;
diff --git a/birthday.man b/birthday.man
index f0f0f6f..2fcde03 100644
--- a/birthday.man
+++ b/birthday.man
@@ -18,6 +18,7 @@ birthday \- warn about upcoming birthdays and other events
 .IR total ]
 .RB [ -i
 .IR width ]
+.RB [ -L ]
 
 .SH DESCRIPTION
 The 
@@ -70,6 +71,9 @@ days in advance. This overrides any flag given in the file.
 Warn at least
 .I min
 days in advance. This overrides any flag given in the file.
+.TP
+.B -L
+Also output the day and name of month after the number of days hence.
 
 .SS Calendar Options
 
diff --git a/debian/changelog b/debian/changelog
index 56d7c73..2fb2d87 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+birthday (1.6.2-4.1) unstable; urgency=low
+
+  * NMU
+  * Add a -L option to output day and month name in list view
+
+ -- Matthew Vernon <m...@sanger.ac.uk>  Wed, 20 Mar 2019 15:35:55 +0000
+
 birthday (1.6.2-4) unstable; urgency=low
 
   * New maintainer (Closes: 673226).
-- 
2.17.1

Reply via email to