Commits

Sebastian Freundt committed 7426889

minor, provide dflt_tm() getter/setter and use that in the massaging routine

Signed-off-by: Sebastian Freundt <freundt@ga-group.nl>

Comments (0)

Files changed (1)

 	return tm;
 }
 
+static struct tm
+dflt_tm(const struct dt_dt_s *set)
+{
+/* getter/setter and singleton for SET == NULL */
+	static struct tm tm;
+
+	if (LIKELY(set == NULL && tm.tm_year != 0U)) {
+		/* show what we've got */
+		;
+	} else if (set == NULL) {
+		/* take over the value of now */
+		struct timeval tv = now_tv();
+		tm = now_tm();
+		tm.tm_hour = (tv.tv_sec % 86400U) / 60U / 60U;
+		tm.tm_min = (tv.tv_sec % 3600U) / 60U;
+		tm.tm_sec = (tv.tv_sec % 60U);
+	} else {
+		switch (set->typ) {
+		case DT_YMD:
+			tm.tm_year = set->d.ymd.y;
+			tm.tm_mon = set->d.ymd.m;
+			tm.tm_mday = set->d.ymd.d;
+			tm.tm_hour = set->t.hms.h;
+			tm.tm_min = set->t.hms.m;
+			tm.tm_sec = set->t.hms.s;
+			break;
+		default:
+			/* good question */
+			return (struct tm){};
+		}
+	}
+	return tm;
+}
+
 static struct strpdt_s
 massage_strpdt(struct strpdt_s d)
 {
  * the pieces of code that use the guesser for different reasons */
 	if (UNLIKELY(d.sd.y == 0U)) {
 		static const struct strpd_s d0 = {};
-		struct tm now = now_tm();
+		struct tm now = dflt_tm(NULL);
 
 		if (UNLIKELY(memcmp(&d.sd, &d0, sizeof(d0)) == 0U)) {
 			goto msgg_time;
 	msgg_time:
 		/* same for time values, but obtain those through now_tv() */
 		if (UNLIKELY(!d.st.flags.h_set)) {
-			struct timeval tv = now_tv();
-
-			d.st.h = (tv.tv_sec % 86400U) / 60U / 60U;
+			d.st.h = now.tm_hour;
 			if (LIKELY(d.st.flags.m_set)) {
 				goto out;
 			}
-			d.st.m = (tv.tv_sec % 3600U) / 60U;
+			d.st.m = now.tm_min;
 			if (LIKELY(d.st.flags.s_set)) {
 				goto out;
 			}
-			d.st.s = (tv.tv_sec % 60U);
+			d.st.s = now.tm_sec;
 		}
 	}
 out:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.