-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timezone shifting #499
Comments
This is indeed an issue, but it is entirely my fault. One of the major reasons I started this project because I got bitten by daylight saving unaware dates in Excel. So to get it working I extract dates explicitly in UTC, and initially coded it to then convert to my local timezone Europe/Amsterdam. So far I haven't fixed this to provide an interface to set the default timezone it should convert to. I have some options in mind:
Do you have thoughts on this? |
I have already had some hard times dealing with timezones in another application. I think that the best option would be the second one. This was at least the behavior I was expecting. Please let me know if I can help with somthing. At least I have a lot of PI servers in at least two different time zones to test. |
Added configuration flag for default timezone, closes #499
I merged a fix into develop, you can install it using |
Bug report
Description
I am observing the following behavior regarding timezones. If I use the PISDK library (through the use of the win32com.client.dynamic Dispatch package) the timestamp information are returned as expected. However when I use PIConnect it return the timestamp as GMT+1h. I would expect that it would return as GMT timezone so I could use the pandas tz_convert to put it in the correct timezone.
To Reproduce
This is tests I am running.
test1.py
from win32com.client.dynamic import Dispatch
from datetime import datetime
import pandas as pd
PL = Dispatch("PISDK.PISDK")
server = PL.Servers("your server here")
tags = ['your tag here']
t_ini = datetime(2019,12,16,8,25,0)
t_end = datetime(2019,12,16,9,35,0)
tag = server.PIPoints(tags[0])
t_inis = t_ini.strftime('%Y-%m-%d %H:%M:%S')
t_ends = t_end.strftime('%Y-%m-%d %H:%M:%S')
L=[]
nValues = (t_end-t_ini).total_seconds()/60+1
pvs = tag.Data.InterpolatedValues(t_inis,t_ends,nValues,1,1,None)
for pv in pvs:
L.append((tags[0],str(pv.Timestamp.LocalDate),str(pv.Value)))
df1 = pd.DataFrame(L,columns=['tag','time','value'])
test2.py
import PIconnect as PI
from datetime import datetime
import pandas as pd
t_ini = datetime(2019,12,16,8,35,0)
t_end = datetime(2019,12,16,9,35,0)
ti = t_ini.strftime('%Y-%m-%d %H:%M:%S')
te = t_end.strftime('%Y-%m-%d %H:%M:%S')
server = PI.PIServer(server='your server here')
points = server.search('your tag here')[0]
data = points.interpolated_values(ti, te,'1m')
data = data.tz_convert(tz='America/Sao_Paulo')
df = pd.DataFrame(data)
Expected behavior
Both code should return the same time frame. But they are shifted by one our. I am at America/Sao_Paulo timezone.
A clear and concise description of what you expected to happen.
Possible solutions
I initially though that this could be a configuration problem in the server but I check it and it seems to be ok. And reading using the PISDK is working.
System
The text was updated successfully, but these errors were encountered: