Skip to content

Fix {timestamp} substitution on Windows - #169

Merged
dolfinus merged 1 commit into
dolfinus:masterfrom
TohruSu:fix-timestamp-windows
Nov 12, 2026
Merged

dolfinus merged 1 commit into
dolfinus:masterfrom
TohruSu:fix-timestamp-windows

Conversation

@TohruSu

@TohruSu TohruSu commented Nov 12, 2026

Copy link
Copy Markdown

Change Summary

On Windows, any template that uses {timestamp} without a format, or with %s, fails:

ValueError: Invalid format string

The default format is strftime("%s"), and Windows' strftime doesn't support %s. It only works on Linux and macOS because their C library happens to have it. Windows isn't in the CI matrix anymore, so nothing caught this.

Now the unix timestamp is computed with int(now.timestamp()) when the format is %s or empty. Other formats still go through strftime.

The existing test_substitution_timestamp cases also used dt.strftime("%s") to build the expected value, so on Windows they failed before the plugin was even called. I switched those to int(dt.timestamp()) and added a test that fakes a strftime without %s support, so it fails on Linux too without the fix.

Mixed formats like {timestamp:%Y%s} are still platform-dependent, same as before, and so is the {timestamp:%i} test case.

I only tested this on Windows with Python 3.14. The timestamp tests pass now. The 13 tests that still fail there ({timestamp:%i}, *_git_missing, *_git_not_executable) fail the same way on master.

Checklist

  • Commit message and PR title is comprehensive
  • Keep the change as small as possible
  • Unit and integration tests for the changes exist
  • Tests pass on CI and coverage does not decrease
  • Documentation reflects the changes where applicable
  • docs/changelog/next_release/<pull request or issue id>.<change type>.rst file added describing change
    (see CONTRIBUTING.rst for details.)
  • My PR is ready to review.

strftime("%s") is not supported on Windows and raises ValueError, so
{timestamp}, {timestamp:} and {timestamp:%s} failed there. Compute the
unix timestamp from datetime.timestamp() instead.
@TohruSu
TohruSu requested a review from dolfinus as a code owner November 12, 2026 10:20

@dolfinus dolfinus left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dolfinus
dolfinus merged commit b88d1f7 into dolfinus:master Nov 12, 2026
9 of 10 checks passed
@TohruSu
TohruSu deleted the fix-timestamp-windows branch November 12, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants