Skip to content
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

Closed
ldariva opened this issue Dec 16, 2019 · 3 comments · Fixed by #500
Closed

Timezone shifting #499

ldariva opened this issue Dec 16, 2019 · 3 comments · Fixed by #500

Comments

@ldariva
Copy link

ldariva commented Dec 16, 2019

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

  • OS: [e.g. Windows]
  • Python version: [Python 3.7]
  • PIconnect version: [e.g. 0.7.1]
@Hugovdberg
Copy link
Owner

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:

  1. Try to figure out the local timezone. As far as I can see this isn't entirely trivial, especially regarding the daylight savings problem.
  2. Set the default timezone to UTC and allow the user to override this using some configuration flag like PIconnect.default_timezone.

Do you have thoughts on this?

@ldariva
Copy link
Author

ldariva commented Dec 16, 2019

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.

Hugovdberg added a commit that referenced this issue Jan 3, 2020
Added configuration flag for default timezone, closes #499
@Hugovdberg
Copy link
Owner

I merged a fix into develop, you can install it using pip install git+https://github.com/Hugovdberg/PIconnect@develop, it will take some more time to get into master and on PyPI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants