From 9cdf8e9af28cc9de5b561d423874b2b61bcae7c6 Mon Sep 17 00:00:00 2001 From: badra001 Date: Fri, 16 Jan 2026 11:05:53 -0500 Subject: [PATCH] make timezone-aware --- local-app/python-tools/sso-tools/README.md | 14 ++++++++++++++ .../python-tools/sso-tools/sso-create-sc-group.py | 14 +++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/local-app/python-tools/sso-tools/README.md b/local-app/python-tools/sso-tools/README.md index 6920234a..eaf20f90 100644 --- a/local-app/python-tools/sso-tools/README.md +++ b/local-app/python-tools/sso-tools/README.md @@ -112,9 +112,23 @@ Because `created_time` is now an object rather than a pre-formatted string, you * **Full Time with Seconds**: `{{ created_time.strftime('%H:%M:%S') }}` * **Year Only**: `{{ created_time.year }}` +### Working with Timezones in Jinja2 + +Since `created_time` now includes timezone data, you can output it in various ways in your templates: + +* **Standard ISO with Offset**: `{{ created_time.isoformat() }}` +* *Output: 2026-01-16T16:04:32.123456+00:00* + + +* **Specific Format**: `{{ created_time.strftime('%Y-%m-%d %H:%M %Z') }}` +* *Output: 2026-01-16 16:04 UTC* ## CHANGELOG +#### v1.0.7 + +* Switched `created_time` to a timezone-aware UTC `datetime` object to ensure consistent timestamps across different server locations. + #### v1.0.6 * Changed `created_time` from a string to a native Python `datetime` object, allowing for custom formatting within Jinja2 templates using `.strftime()`. diff --git a/local-app/python-tools/sso-tools/sso-create-sc-group.py b/local-app/python-tools/sso-tools/sso-create-sc-group.py index 448e87ed..7d261a1a 100755 --- a/local-app/python-tools/sso-tools/sso-create-sc-group.py +++ b/local-app/python-tools/sso-tools/sso-create-sc-group.py @@ -4,13 +4,13 @@ import sys import os from pathlib import Path -from datetime import datetime +from datetime import datetime, timezone from jinja2 import Environment, FileSystemLoader # Version History: -# 1.0.0 - 1.0.5: Basic logic, lowercase, force, description, metadata strings -# 1.0.6: Passed created_time as a datetime object for flexible template formatting -__version__ = "1.0.6" +# 1.0.0 - 1.0.6: Logic, lowercase, force, metadata, datetime object +# 1.0.7: Made created_time timezone-aware (UTC) +__version__ = "1.0.7" def create_sc_group(): parser = argparse.ArgumentParser(description="Automate file creation from templates.") @@ -23,9 +23,9 @@ def create_sc_group(): args = parser.parse_args() - # 1. Setup metadata + # 1. Setup metadata (Timezone Aware) script_name = os.path.basename(__file__) - now = datetime.now() # Native datetime object + now = datetime.now(timezone.utc) # 2. Determine names and force to lowercase raw_group = args.group if args.group else Path.cwd().name @@ -67,7 +67,7 @@ def create_sc_group(): "description": args.description or "", "script_name": script_name, "version": __version__, - "created_time": now # Passed as object + "created_time": now } # 8. Process files