Repository navigation
Fix {timestamp} substitution on Windows - #169
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Summary
On Windows, any template that uses
{timestamp}without a format, or with%s, fails:The default format is
strftime("%s"), and Windows'strftimedoesn'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%sor empty. Other formats still go throughstrftime.The existing
test_substitution_timestampcases also useddt.strftime("%s")to build the expected value, so on Windows they failed before the plugin was even called. I switched those toint(dt.timestamp())and added a test that fakes astrftimewithout%ssupport, 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
docs/changelog/next_release/<pull request or issue id>.<change type>.rstfile added describing change(see CONTRIBUTING.rst for details.)