Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions folder_paths.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import re
import time
import mimetypes
import logging
Expand Down Expand Up @@ -376,6 +377,21 @@ def compute_vars(input: str, image_width: int, image_height: int) -> str:
input = input.replace("%hour%", str(now.tm_hour).zfill(2))
input = input.replace("%minute%", str(now.tm_min).zfill(2))
input = input.replace("%second%", str(now.tm_sec).zfill(2))

# Handle %date:FORMAT%
def date_repl(match):
fmt = match.group(1)
# Map Java-like formatting to strftime where possible
fmt = (fmt.replace("yyyy", "%Y")
.replace("MM", "%m")
.replace("dd", "%d")
.replace("hh", "%H")
.replace("mm", "%M")
.replace("ss", "%S"))
return time.strftime(fmt, now)

input = re.sub(r"%date:(.*?)%", date_repl, input)

return input

if "%" in filename_prefix:
Expand Down