mirror of
https://github.com/samba-team/samba.git
synced 2025-01-08 21:18:16 +03:00
netcmd: models: model field DateTimeField returns datetime in UTC
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
10ef49b049
commit
4c08b420dd
@ -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."""
|
||||
|
@ -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),
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user