From 5a981310e68253c77f9fe3144d247cfd531f9e48 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Sun, 23 Oct 2022 18:09:21 +0900 Subject: [PATCH] replace_datetime() can now accept a datetime parameter --- modules/images.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/images.py b/modules/images.py index 321439e3..ff00fc52 100644 --- a/modules/images.py +++ b/modules/images.py @@ -303,7 +303,7 @@ def apply_filename_pattern(x, p, seed, prompt): x = re.sub(r'\[model_hash]', getattr(p, "sd_model_hash", shared.sd_model.sd_model_hash), x, flags=re.IGNORECASE) x = re.sub(r'\[date]', datetime.date.today().isoformat(), x, flags=re.IGNORECASE) - x = replace_datetime(x) + x = replace_datetime(x, datetime.datetime.now()) x = re.sub(r'\[job_timestamp]', getattr(p, "job_timestamp", shared.state.job_timestamp), x, flags=re.IGNORECASE) # Apply [prompt] at last. Because it may contain any replacement word.^M if prompt is not None: @@ -353,8 +353,14 @@ def get_next_sequence_number(path, basename): return result + 1 -def replace_datetime(input_str: str): +def replace_datetime(input_str: str, time_datetime: datetime.datetime = None): """ + Args: + input_str (`str`): + the String to be Formatted + time_datetime (`datetime.datetime`) + the time to be used, if None, use datetime.datetime.now() + Formats sub_string of input_str with formatted datetime with time zone support. accepts sub_string format: [datetime], [datetime], [datetime