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

[BUG] - get_plc_time does not account for timezones when converting to datetime #276

Open
3 tasks done
ronytigo opened this issue May 1, 2023 · 4 comments
Open
3 tasks done
Labels
bug Something isn't working

Comments

@ronytigo
Copy link

ronytigo commented May 1, 2023

Pre-checks

  • running latest version
  • enabled logging
  • consulted the docs

Description
time received ignores the timezone of the plc. For example, the plc timezone is GMT + 3 and the time is set to 8pm, the code will receive 8pm instead of 5pm which is the gmt time. If I go to https://www.epochconverter.com and enter the microseconds field I get from plc.get_plc_time().value['microseconds'] it shows 8pm in GMT and 11pm in local (the correct timestamp should show 5pm in GMT and 8pm in local timezone).

Target PLC
Rockwell Automation/Allen-Bradley
Model: 1756-L83E/B
Firmware Revision: 33.11

Code Sample
Minimal reproduceable code sample

LogixDriver(url, init_tags=False, init_program_tags=False) as plc:
    plc.get_plc_time().value['microseconds']

Additional context

  • if reading/writing a tag, describe it's type/structure/etc
  • attach any relevant L5X or data files
  • paste/attach logging output
@ronytigo ronytigo added the bug Something isn't working label May 1, 2023
@ottowayi ottowayi changed the title [BUG] - [BUG] - get_plc_time does not account for timezones when converting to datetime May 16, 2023
@ottowayi
Copy link
Owner

You're right, this method reads attribute 11 from the WallClockTime object, which is the unix local time. Attribute 6 is the utc unix time, which I think should fix the issue. I don't do a lot with datetime objects in Python, but I think passing the utc timezone when constructing the datetime object should also be done.

If you want to create a PR for this issue, you may and I can help with it, else I'll try to get it fixed soon.

@jbolognini
Copy link

I implemented the fix for this, was simple modification of the get_plc_time method, passing in the time zone like you suggested and using attribute 6. Do you prefer I perform the fix from the main branch? I am new to GitHub but will attempt to do the PR and commit push.

@ottowayi
Copy link
Owner

ottowayi commented Nov 3, 2023

sorry for the late response, targeting master is fine. I may change it into a dev branch before merging, but don't worry about that. The basic steps would be to fork my repo (the Fork button at the top of the page), then create a branch for this fix, check that branch out in your IDE, make the code changes, commit and push those changes to your new branch, then in github create a new pull request back to my repo targeting the master branch.

@jbolognini
Copy link

ok i did as you instructed, thanks for the help. pull request pending.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants