-
Notifications
You must be signed in to change notification settings - Fork 1
/
datetime_formatter_node.py
31 lines (26 loc) · 1.03 KB
/
datetime_formatter_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import datetime
class NowFormatterNode:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"format": ("STRING", {"default": "yyyy-MM-dd-hhmmss"}), # Default format
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("formatted_datetime",)
FUNCTION = "format_datetime"
CATEGORY = "utils"
def format_datetime(self, format: str) -> tuple[str]:
# Convert custom format to strftime format
format = format.replace("yyyy", "%Y").replace("MM", "%m").replace("dd", "%d").replace("hh", "%H").replace("mm", "%M").replace("ss", "%S")
# Get the current time and format it
try:
current_time = datetime.datetime.now()
formatted_time = current_time.strftime(format) # Use the user-provided format directly
return formatted_time,
except ValueError as e:
raise ValueError(f"Invalid format: {str(e)}")
@classmethod
def IS_CHANGED(cls, **kwargs):
return float("NaN")