Skip to content

Make Docutils date substitutions honor SOURCE_DATE_EPOCH across supported versions #14769

Open

Description

@Darlokt

Describe the bug

Hej,
This follows up on the SOURCE_DATE_EPOCH item tracked in #14680.
Docutils added support for SOURCE_DATE_EPOCH in its date directive in r10402, during development of Docutils 1.0.
Sphinx already honors the variable for its |today| substitution. However, with pre-1.0 Docutils versions, the standard date directive still inserts the machine’s current date. The same document therefore produces different date substitutions depending on the installed Docutils version.
Sphinx should ideally provide consistent epoch-based date substitutions across supported Docutils versions and add regression coverage for the native Docutils 1.0 behavior.

How to Reproduce

Create docs/conf.py:

today_fmt = '%Y-%m-%d'

Create docs/index.rst:

Date substitutions
==================

.. |docutils-date| date:: %Y-%m-%d

Docutils: |docutils-date|

Sphinx: |today|

On unpatched Sphinx, run:

SOURCE_DATE_EPOCH=1439131307 uv run sphinx-build -b text docs _build/text

With pre-1.0 Docutils, the Sphinx substitution produces 2015-08-09, while the Docutils substitution produces the machine’s current date.

Expected: Both substitutions produce 2015-08-09, using the supplied timestamp in UTC.

Compatibility handling should preserve custom date formats, existing behavior when the variable is unset, invalid-context diagnostics, and extension overrides. Docutils 1.0 should retain ownership of its native implementation.

Environment Information

Platform:              linux; (Linux-6.18.33.2-microsoft-standard-WSL2-x86_64-with-glibc2.39)
Python version:        3.14.7 (main, Aug 14 2026, 15:35:28) [Clang 22.1.3 ])
Python implementation: CPython
Sphinx version:        9.1.1+/eba6d9d84
Docutils version:      0.22.3
Jinja2 version:        3.1.6
Pygments version:      2.19.2

Sphinx extensions

[]

Additional context

I think this fits in with existing SOURCE_DATE_EPOCH work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions