Commits

Sebastian Freundt  committed 8737bb0 Merge

Merge branch 'next'

* next:
minor, provide author and bug info in man pages
minor, char dt_get_quarter()'s result and print
fix, PEBKAC, actually decalre dt_get_quarter()
minor, do not overwrite d.m if month has been set already
minor, read quarter information into d.m
minor, document %q and %Q
minor, support %q and %Q in dt_strpd()
minor, support %q and %Q in dt_strfd()
minor, use %> for bizda reference specs

  • Participants
  • Parent commits 397f8d3, 79bc4b8
  • Tags v0.1.4rc2

Comments (0)

Files changed (5)

File info/Makefile.am

 
 
 dateutils_H2M_EX += format.h2m
+dateutils_H2M_EX += author.h2m
 
 BUILT_SOURCES += $(dateutils_TEXINFOS) $(dateutils_H2M_EX)
 
 	$(my_bld_man) $(HELP2MAN) -S "$(PACKAGE_STRING)" -p "($(PACKAGE))$*" \
 		-I "$(srcdir)/$*.h2m" -I "$(builddir)/$*.h2m" \
 		-I "$(srcdir)/format.h2m" -I "$(builddir)/format.h2m" \
+		-I "$(srcdir)/author.h2m" \
 		-o $@ $(top_builddir)/src/$*
 
 my_bld_h2m = $(__bld_h2m_$(V))

File info/author.h2m

+[AUTHOR]
+  Written by Sebastian Freundt <freundt@fresse.org>
+
+[BUGS]
+  Report them to: https://github.com/hroptatyr/dateutils/issues
+

File info/format.texi

   %F  Equivalent to %Y-%m-%d (ymd's canonical format)
   %j  The day of the year
   %m  The month in the current calendar (range 00 to 19)
+  %Q  The quarter of the year (range Q1 to Q4)
+  %q  The number of the quarter (range 01 to 04)
   %w  The weekday as number (range 00 to 06, Sunday being 00)
   %y  The year without a century (range 00 to 99)
   %Y  The year including the century

File lib/date-core.c

 	}
 }
 
+DEFUN int
+dt_get_quarter(struct dt_d_s that)
+{
+	int m;
+
+	switch (that.typ) {
+	case DT_YMD:
+		m = that.ymd.m;
+		break;
+	case DT_YMCW:
+		m = that.ymcw.m;
+		break;
+	case DT_BIZDA:
+		m = that.bizda.m;
+		break;
+	default:
+	case DT_UNK:
+		return 0;
+	}
+	return (m - 1) / 3 + 1;
+}
+
 
 /* converters */
 static dt_daisy_t
 				d.y -= 100;
 			}
 			break;
-		case 'q':
+		case '>':
 			/* bizda date and we take the arg from sp */
 			switch (*sp++) {
 			case '<':
 			/* cannot be used at the moment */
 			strtoui_lim(sp, &sp, 0, 53);
 			break;
+		case 'Q':
+			if (*sp++ != 'Q') {
+				sp = str;
+				goto out;
+			}
+		case 'q':
+			if (d.m == 0) {
+				d.m = strtoui_lim(sp, &sp, 1, 4) * 3 - 2;
+			}
+			break;
 		case 'O':
 			/* roman numerals modifier */
 			switch (*++fp) {
 			res += ui32tostr(buf + res, bsz - res, d.y, 2);
 			break;
 		case 'q':
+		case 'Q': {
+			int q = dt_get_quarter(that);
+
+			if (q <= 4) {
+				if (*fp == 'q') {
+					buf[res++] = '0';
+				} else if (*fp == 'Q') {
+					buf[res++] = 'Q';
+				}
+				buf[res++] = (char)(q + '0');
+			}
+			break;
+		}
+		case '>':
 			/* bizda mode check? */
 			if (((d.flags >> 1) & 1) == BIZDA_AFTER) {
 				buf[res++] = '>';

File lib/date-core.h

 DECLF int dt_get_bday_q(struct dt_d_s d, unsigned int ba, unsigned int ref);
 
 /**
+ * Get the quarter number of a date. */
+DECLF int dt_get_quarter(struct dt_d_s d);
+
+/**
  * Get the day of the year of a date.
  * This might only be intuitive for YMD dates.  The formal definition
  * is to find a representation of D that lacks the notion of a month,