opcua-asyncio icon indicating copy to clipboard operation
opcua-asyncio copied to clipboard

SourceTimestamp and ServerTimestamp created as naive Datetime?

Open oisene opened this issue 5 years ago • 8 comments

In async.ua.uatypes at line 21 we have:

FILETIME_EPOCH_AS_DATETIME = datetime(1601, 1, 1)

I am happy to be corrected, but to me this creates what the Python documentation calls a naive datetime, that is, without time zone information, and this will return the time local to my time zone.

In other words, these return different results; shouldn't the last one be used?

datetime(1601,1,1).timestamp()
datetime(1601,1,1,tzinfo=timezone.utc).timestamp()

(All timestamps in the OPC UA standard are in UTC, AFAIK)

oisene avatar Aug 07 '19 19:08 oisene

You are probably correct. When I wrote that code, there were many issues with time zones in python. Maybe it works now. Send a PR

oroulet avatar Aug 07 '19 20:08 oroulet

Thanks for quick response; I will after some testing.

oisene avatar Aug 07 '19 20:08 oisene

Changing it to an "aware" Datetime breaks a lot of the tests. Also using the official timestamp for 1601-01-01 (-11644473600) breaks quite a few tests, looks there are still many issues with datetime in Python for dates pre-Gregorian calendar. In my own tests I get errors when converting between UTC and local time for the date mentioned above.

oisene avatar Aug 08 '19 13:08 oisene

Hi there! Are there some news on that? All SourceTimestamps are UTC and I'll be glad to set another timezone once, instead of forcing clients to make assumptions and to adjust them from the client side

pbertoni89 avatar Dec 10 '21 09:12 pbertoni89

I have not heard anything so I suppose the state is the same. you are welcome to give it a shot @pbertoni89

oroulet avatar Dec 10 '21 09:12 oroulet

in datetime you can set "tzinfo" (https://docs.python.org/3/library/datetime.html#datetime.datetime.tzinfo) if it is "None" its UTC anyways.

AndreasHeine avatar Dec 10 '21 09:12 AndreasHeine

looking at code I see that we call datetime.utcnnow() everywhere so I think the timezone is set in fact. Does that issue really exist @pbertoni89 ?

oroulet avatar Dec 10 '21 09:12 oroulet

Well I'm not very proficient in the library itself (I'm a novice both in OPCUA and ASYNCIO), however I see

$ grep -rIn timezone | grep -v tests

asyncua/common/xmlparser.py:263: # According to specs, DateTime should be either UTC or with a timezone. asyncua/ua/uatypes.py:13:from datetime import datetime, timedelta, MAXYEAR, timezone asyncua/ua/uatypes.py:45:FILETIME_EPOCH_AS_UTC_DATETIME = FILETIME_EPOCH_AS_DATETIME.replace(tzinfo=timezone.utc) asyncua/server/event_generator.py:95: self.event.LocalTime.Offset = -(time.altzone if localtime.tm_isdst else time.timezone)

So my question was incorrectly formed, in facts I'd just change somehow the timezone of a running server, because my local time is not fetched (I'm in CET right now). I apologize for any misunderstanding

pbertoni89 avatar Dec 10 '21 18:12 pbertoni89