Description: Make the build reproducible
Author: Chris Lamb <lamby@debian.org>
Last-Update: 2016-08-22

Index: dateutils-0.4.10/build-aux/yuck.c
===================================================================
--- dateutils-0.4.10.orig/build-aux/yuck.c	2023-02-02 18:37:22.603100924 +0000
+++ dateutils-0.4.10/build-aux/yuck.c	2023-02-02 18:37:22.591100073 +0000
@@ -1425,6 +1425,38 @@
 	return rc;
 }
 
+static time_t
+get_current_time(void)
+{
+	time_t now;
+	char *source_date_epoch, *endptr;
+	unsigned long long epoch;
+
+	source_date_epoch = getenv("SOURCE_DATE_EPOCH");
+
+	if (!source_date_epoch) {
+		return time(NULL);
+	}
+
+	errno = 0;
+	epoch = strtoull(source_date_epoch, &endptr, 10);
+
+	if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0)) || (errno != 0 && epoch == 0)) {
+		now = (time_t)-1;
+	} else if (endptr == source_date_epoch) {
+		now = (time_t)-1;
+	} else if (*endptr != '\0') {
+		now = (time_t)-1;
+	} else if (epoch > ULONG_MAX) {
+		now = (time_t)-1;
+	} else {
+		now = (time_t)epoch;
+	}
+
+	return now;
+}
+
+
 
 static int
 wr_pre(void)
@@ -1508,7 +1540,7 @@
 	char buf[32U];
 	int rc = 0;
 
-	if ((now = time(NULL)) == (time_t)-1) {
+	if ((now = get_current_time()) == (time_t)-1) {
 		rc = -1;
 	} else if ((tp = gmtime(&now)) == NULL) {
 		rc = -1;
