Skip to content

Commit 7c1d80a

Browse files
committed
updated the date metadata code based on PR feedback
1 parent df1fa3b commit 7c1d80a

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

detection_rules/main.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,13 @@ def import_rules_into_repo( # noqa: PLR0912, PLR0913, PLR0915
248248
contents["author"] = [contents["author"]]
249249

250250
# Parse created_at and updated_at to creation_date and updated_date if they exist in contents
251-
if "created_at" in contents:
252-
try:
253-
contents["creation_date"] = datetime.strptime(
254-
contents["created_at"], "%Y-%m-%dT%H:%M:%S.%fZ"
255-
).strftime("%Y/%m/%d")
256-
except ValueError:
257-
pass
258-
259-
if "updated_at" in contents:
260-
try:
261-
contents["updated_date"] = datetime.strptime(
262-
contents["updated_at"], "%Y-%m-%dT%H:%M:%S.%fZ"
263-
).strftime("%Y/%m/%d")
264-
except ValueError:
265-
pass
251+
now = datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
252+
contents["creation_date"] = datetime.strptime(
253+
contents.get("created_at", now), "%Y-%m-%dT%H:%M:%S.%fZ"
254+
).strftime("%Y/%m/%d")
255+
contents["updated_date"] = datetime.strptime(contents.get("updated_at", now), "%Y-%m-%dT%H:%M:%S.%fZ").strftime(
256+
"%Y/%m/%d"
257+
)
266258

267259
contents.update(
268260
update_metadata_from_file(

0 commit comments

Comments
 (0)