aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sisudoc/ocda
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2026-09-21 00:25:19 -0400
committerRalph Amissah <ralph.amissah@gmail.com>2026-09-22 13:09:35 -0400
commit515c44399843c62336a0102e933f9fbd7289743d (patch)
tree97cb7a699872c7d235a5833933c415458aff074e /src/sisudoc/ocda
parentmetadata: use document's language (diff)
odt: office:meta from the document, not the run
Three faults in four lines of the odt metadata. meta:creation-date and dc:date were taken from generated_time, the run's own clock, so two runs over unchanged markup produced different odt bytes. They now carry the document's own instant, so an odt is a function of its source. That was the last clock stamp in any writer: every output format is now reproducible. generated_time is a human-readable run stamp, of the form "2026-9-17 [38/3] 18:39:35", with unpadded numbers and an iso week in brackets. It is not a valid xsd:dateTime, which is what ODF asks for in both of those fields, so what was written there was malformed as well as unstable. dc:language now carries the document's own language tag. The instant is doc_matters.modified_utc, moved there from epub3.d in this commit: epub3 needs the same value for its dcterms:modified, and one definition cannot drift from the other. generated_time now has no caller and is left in place. (assisted by Claude-Code)
Diffstat (limited to 'src/sisudoc/ocda')
-rw-r--r--src/sisudoc/ocda/meta/doc_matters.d72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/sisudoc/ocda/meta/doc_matters.d b/src/sisudoc/ocda/meta/doc_matters.d
index 19e3d0f..ff528d5 100644
--- a/src/sisudoc/ocda/meta/doc_matters.d
+++ b/src/sisudoc/ocda/meta/doc_matters.d
@@ -116,6 +116,78 @@ template spineDocMatters() {
}
return Prog_();
}
+ /+ ↓ when the document is from, as a UTC instant, for the output formats
+ that must carry a timestamp: epub3 requires exactly one
+ dcterms:modified on the package, and an odt carries
+ meta:creation-date and dc:date.
+ .
+ Taken from the document rather than from the clock, so that those
+ artefacts are a function of their source. Stamped from the clock,
+ two runs over unchanged markup produced different bytes, and no
+ comparison of that output could tell a real change from the
+ seconds between two builds.
+ .
+ Read in order: SOURCE_DATE_EPOCH where the environment sets it,
+ which is the reproducible-builds convention and lets a build pin
+ every artefact of one run; then the document's own date.modified;
+ then date.published. The clock is the last resort, for a document
+ that says nothing about when it is from.
+ .
+ A document date is loose markup: "1991", "2006-03" and
+ "2021-12-00" all occur in the sample set, and a month or day of 00
+ is not a date. A missing or zero part becomes 01, and a day out of
+ range for its month falls back to the first, so what is written is
+ always a valid CCYY-MM-DDThh:mm:ssZ.
+ +/
+ string modified_utc() {
+ import std.datetime : Date, SysTime, unixTimeToStdTime;
+ import std.format : format;
+ import std.process : environment;
+ import std.regex : ctRegex, matchFirst;
+ /+ ↓ a build may pin every artefact of the run +/
+ string _sde = environment.get("SOURCE_DATE_EPOCH", "");
+ if (_sde.length > 0) {
+ try {
+ auto _t = SysTime(unixTimeToStdTime(_sde.to!long), UTC());
+ return format("%04d-%02d-%02dT%02d:%02d:%02dZ",
+ _t.year, _t.month.to!int, _t.day, _t.hour, _t.minute, _t.second);
+ } catch (Exception) {
+ }
+ }
+ /+ ↓ what the document itself says +/
+ auto _rgx_date
+ = ctRegex!(`^\s*(?P<y>\d{4})(?:[-/](?P<m>\d{1,2}))?(?:[-/](?P<d>\d{1,2}))?`);
+ foreach (_said; [
+ conf_make_meta.meta.date_modified,
+ conf_make_meta.meta.date_published,
+ ]) {
+ if (_said.length == 0) {
+ continue;
+ }
+ if (auto _m = _said.matchFirst(_rgx_date)) {
+ int _y = _m["y"].to!int;
+ int _mo = (_m["m"].length > 0) ? _m["m"].to!int : 1;
+ int _d = (_m["d"].length > 0) ? _m["d"].to!int : 1;
+ if (_mo < 1 || _mo > 12) {
+ _mo = 1;
+ }
+ if (_d < 1) {
+ _d = 1;
+ }
+ try {
+ cast(void) Date(_y, _mo, _d);
+ } catch (Exception) {
+ _d = 1;
+ }
+ return format("%04d-%02d-%02dT00:00:00Z", _y, _mo, _d);
+ }
+ }
+ /+ ↓ the document says nothing: the run's own time +/
+ auto _now = Clock.currTime(UTC());
+ return format("%04d-%02d-%02dT%02d:%02d:%02dZ",
+ _now.year, _now.month.to!int, _now.day,
+ _now.hour, _now.minute, _now.second);
+ }
auto generated_time() {
auto _st = Clock.currTime(UTC());
auto _time = _st.year.to!string