From 33d639bc139749dc045f43744212826f3129a8ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cohen?= Date: Tue, 25 Jul 2023 10:35:42 +0200 Subject: [PATCH] fix: Ensure year is always 4 digits --- stix2/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stix2/utils.py b/stix2/utils.py index 8f679d43..ee468eea 100644 --- a/stix2/utils.py +++ b/stix2/utils.py @@ -18,8 +18,8 @@ PREFIX_21_REGEX = re.compile(r'^[a-z].*') -_TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%SZ" -_TIMESTAMP_FORMAT_FRAC = "%Y-%m-%dT%H:%M:%S.%fZ" +_TIMESTAMP_FORMAT = "%4Y-%m-%dT%H:%M:%SZ" +_TIMESTAMP_FORMAT_FRAC = "%4Y-%m-%dT%H:%M:%S.%fZ" class Precision(enum.Enum): @@ -167,7 +167,7 @@ def format_datetime(dttm): zoned = pytz.utc.localize(dttm) else: zoned = dttm.astimezone(pytz.utc) - ts = zoned.strftime('%Y-%m-%dT%H:%M:%S') + ts = zoned.strftime('%4Y-%m-%dT%H:%M:%S') precision = getattr(dttm, 'precision', Precision.ANY) precision_constraint = getattr( dttm, 'precision_constraint', PrecisionConstraint.EXACT,