Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.25 KB

timezones.rst

File metadata and controls

42 lines (30 loc) · 1.25 KB

Configuring timezones

Warning

Default timezone changed from Europe/Amsterdam to UTC in 0.8.0

By default the data is extracted in the UTC timezone. This is done since no fool proof way is available to detect the local timezone. It is however possible to configure the timezone used by PIconnect. This is done using the :data:`PIConfig.DEFAULT_TIMEZONE <PIconnect.config.PIConfigContainer.DEFAULT_TIMEZONE>` option. It takes any valid pytz timezone name, such as Europe/Amsterdam or America/Sao_Paulo.

import PIconnect as PI

print(PI.PIConfig.DEFAULT_TIMEZONE)
with PI.PIServer() as server:
    points = server.search('*')
    data = points[0].recorded_values('-1h', '*')

print(data.index.tz)

PI.PIConfig.DEFAULT_TIMEZONE = 'Etc/GMT-1'

with PI.PIServer() as server:
    points = server.search('*')
    data = points[0].recorded_values('-1h', '*')

print(data.index.tz)

The output is always a :any:`pandas.Series` object with a timezone aware :any:`pandas.DatetimeIndex`, so it is also possible to convert the timezone afterwards like:

data.index = data.index.tz_convert('Europe/Amsterdam')