Open ntbloom opened 1 year ago
This is normal, opc ua timestamps are always utc
I understand that the server handles timezones and always returns UTC time. The issue is that it makes it difficult to compare values if you pass in a timezone aware object and are returned a timezone naive object. I don't think it's reasonable to expect that all uatypes.DateTime
objects should be returned with a tzinfo
attribute of timezone.utc
(that could break some users), but if the value that's passed into the server is timezone aware, shouldn't the returned value also be timezone aware?
i guess this could be an issue... https://github.com/FreeOpcUa/opcua-asyncio/blob/a8091a44dbf9959f37d84e39d15e3110acdd69e2/asyncua/ua/uatypes.py#L188
i am not sure if you can assume that a "Python DateTime" and a "OPC UA DateTime" are the same which means the native comparing might be not correct...
https://reference.opcfoundation.org/Core/Part6/v105/docs/5.2.2.5 https://reference.opcfoundation.org/Core/Part6/v105/docs/5.4.2.6 https://reference.opcfoundation.org/Core/Part6/v105/docs/5.3.1.6
i would convert the datetime to the 64bit signed int and compare those rather then the datetime itself!
Yes, there are different ways to workaround and this is not currently blocking me in any way. My guess is that inheriting DateTime
from int
instead of Datetime
might be a longterm goal in order to be more compliant with the spec, but again that would almost certainly break a lot of existing code. I'm happy to close the issue if that's the sanest option.
Describe the bug
When adding a variable to an object of the
uatypes.DateTime
type, when we read the value from the server, the timezone is preserved. When reading from the client, the tzinfo attribute is discarded.To Reproduce
The following code snippet should document the exact problem:
Here are the results of running this:
Expected behavior
I expect the client to return an equivalent value to what gets retrieved by the server.
Version
Python-Version:3.11.4
opcua-asyncio Version (e.g. master branch, 0.9): 1.0.3