diff --git a/python/samba/netcmd/domain/models/fields.py b/python/samba/netcmd/domain/models/fields.py index 117d805fd4b..1a4d9d7f034 100644 --- a/python/samba/netcmd/domain/models/fields.py +++ b/python/samba/netcmd/domain/models/fields.py @@ -22,7 +22,7 @@ import io from abc import ABCMeta, abstractmethod -from datetime import datetime +from datetime import datetime, timezone from enum import IntEnum, IntFlag from xml.etree import ElementTree @@ -221,10 +221,11 @@ class DateTimeField(Field): if value is None: return elif len(value) > 1 or self.many: - return [datetime.fromtimestamp(string_to_time(str(item))) - for item in value] + return [datetime.fromtimestamp(string_to_time(str(item)), + tz=timezone.utc) for item in value] else: - return datetime.fromtimestamp(string_to_time(str(value))) + return datetime.fromtimestamp(string_to_time(str(value)), + tz=timezone.utc) def to_db_value(self, ldb, value, flags): """Convert datetime or list of datetime to MessageElement.""" diff --git a/python/samba/tests/samba_tool/domain_models.py b/python/samba/tests/samba_tool/domain_models.py index 45d6095c775..fdfaac2f431 100644 --- a/python/samba/tests/samba_tool/domain_models.py +++ b/python/samba/tests/samba_tool/domain_models.py @@ -21,7 +21,7 @@ # import os -from datetime import datetime +from datetime import datetime, timezone from xml.etree import ElementTree from ldb import FLAG_MOD_ADD, MessageElement, SCOPE_ONELEVEL @@ -194,16 +194,20 @@ class DateTimeFieldTest(FieldTestMixin, SambaToolCmdTest): field = fields.DateTimeField("FieldName") to_db_value = [ - (datetime(2023, 1, 27, 22, 36, 41), MessageElement("20230127223641.0Z")), - ([datetime(2023, 1, 27, 22, 36, 41), datetime(2023, 1, 27, 22, 47, 50)], + (datetime(2023, 1, 27, 22, 36, 41, tzinfo=timezone.utc), + MessageElement("20230127223641.0Z")), + ([datetime(2023, 1, 27, 22, 36, 41, tzinfo=timezone.utc), + datetime(2023, 1, 27, 22, 47, 50, tzinfo=timezone.utc)], MessageElement(["20230127223641.0Z", "20230127224750.0Z"])), (None, None), ] from_db_value = [ - (MessageElement("20230127223641.0Z"), datetime(2023, 1, 27, 22, 36, 41)), + (MessageElement("20230127223641.0Z"), + datetime(2023, 1, 27, 22, 36, 41, tzinfo=timezone.utc)), (MessageElement(["20230127223641.0Z", "20230127224750.0Z"]), - [datetime(2023, 1, 27, 22, 36, 41), datetime(2023, 1, 27, 22, 47, 50)]), + [datetime(2023, 1, 27, 22, 36, 41, tzinfo=timezone.utc), + datetime(2023, 1, 27, 22, 47, 50, tzinfo=timezone.utc)]), (None, None), ]