1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
diff --git a/src/main.c b/src/main.c
index 14b08d2..e2cc33e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,6 +3,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
+#define __USE_XOPEN
#include <time.h>
#include <unistd.h>
#include "string.h"
@@ -66,10 +67,17 @@ static void parse_preamble(struct parser *p) {
int section = -1;
uint32_t ch;
char date[256];
- time_t now;
- time(&now);
- struct tm *now_tm = localtime(&now);
- strftime(date, sizeof(date), "%F", now_tm);
+ char *source_date_epoch = getenv("SOURCE_DATE_EPOCH");
+ if (source_date_epoch != NULL) {
+ struct tm source_date_epoch_tm;
+ strptime(source_date_epoch, "%s", &source_date_epoch_tm);
+ strftime(date, sizeof(date), "%F", &source_date_epoch_tm);
+ } else {
+ time_t now;
+ time(&now);
+ struct tm *now_tm = localtime(&now);
+ strftime(date, sizeof(date), "%F", now_tm);
+ }
while ((ch = parser_getch(p)) != UTF8_INVALID) {
if ((ch < 0x80 && isalnum(ch)) || ch == '_' || ch == '-' || ch == '.') {
assert(str_append_ch(name, ch) != -1);
diff --git a/test/preamble b/test/preamble
index 03e2d0c..eeb734b 100755
--- a/test/preamble
+++ b/test/preamble
@@ -38,31 +38,31 @@ EOF
end 0
begin "Writes the appropriate header"
-scdoc <<EOF | grep '^\.TH "test" "8" "'"$(date +'%F')"'"' >/dev/null
+scdoc <<EOF | grep '^\.TH "test" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'"' >/dev/null
test(8)
EOF
end 0
begin "Preserves dashes"
-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'"' >/dev/null
+scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'"' >/dev/null
test-manual(8)
EOF
end 0
begin "Handles extra footer field"
-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "Footer"' >/dev/null
+scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "Footer"' >/dev/null
test-manual(8) "Footer"
EOF
end 0
begin "Handles both extra fields"
-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "Footer" "Header"' >/dev/null
+scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "Footer" "Header"' >/dev/null
test-manual(8) "Footer" "Header"
EOF
end 0
begin "Emits empty footer correctly"
-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "" "Header"' >/dev/null
+scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "" "Header"' >/dev/null
test-manual(8) "" "Header"
EOF
end 0
|