0

IO Not Adjusting for DST?
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

IO Not Adjusting for DST?

by rspengler on Mon Mar 15, 2021 10:01 am

Hi, I'm newish to using Adafruit IO, and this is the first time I've used it during a DST change. I'm using the MatrixPortal get_local_time query for my timezone (New York), and it appears to be returning the EST adjustment from GMT of -5, rather than the now applicable EDT adjustment of -4, given the DST change Sunday morning. This results in my queries returning results for items an hour ahead of now, as the data I'm querying is correctly showing it as starting at the relevant time in the -4 timezone, which is equivalent to an hour earlier in the -5 timezone.

What do I need to do in my code to make this adjustment, and so that it will correctly adjust every Nov/Mar as the offset for my timezone shifts?

Thanks!

rspengler
 
Posts: 3
Joined: Mon Jan 11, 2021 11:22 pm

Re: IO Not Adjusting for DST?

by jwcooper on Mon Mar 15, 2021 10:54 am

Can you make sure you have the latest version of the libraries? There is a chance you have a version of the Adafruit_CircuitPython_PortalBase that doesn't utilize the location flag properly:
https://github.com/adafruit/Adafruit_Ci ... ll/5/files

jwcooper
 
Posts: 781
Joined: Tue May 01, 2012 9:08 pm

Re: IO Not Adjusting for DST?

by rspengler on Mon Mar 15, 2021 11:51 am

Thanks, I was running an older version, and grabbed the latest listed at https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/tag/20210314. What's happening now is it appears it is still pulling -5 for the American/New_York timezone. However, upon further review of the code, I realized that it was hard-coded into a function I use to set up the right time format for querying Google Calendar. This is my code (now changed to be -4):

Code: Select all | TOGGLE FULL SIZE
def get_current_time(time_max=False):
    """Gets local time from Adafruit IO and converts to RFC3339 timestamp."""
    # Get local time from Adafruit IO, with exception for request failures
    try:
        matrixportal.get_local_time(secrets["timezone"])
    except:
        print("Time query failed, proceeding without updating time.")
    # Format as RFC339 timestamp
    cur_time = time.localtime()
    cur_time = "{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}{:s}".format(
        cur_time[0],
        cur_time[1],
        cur_time[2],
        cur_time[3],
        cur_time[4],
        cur_time[5],
        "-04:00",
    )
    return cur_time


I pulled this function from the MagTag Google Calendar project (see starting at line 81): https://learn.adafruit.com/magtag-google-calendar-event-display/code-usage. There, it uses Z (GMT). I just need to fix it so it's not using a hard-coded timezone adjustment. Thanks for the help, it helped me figure out the culprit at least!

rspengler
 
Posts: 3
Joined: Mon Jan 11, 2021 11:22 pm

Re: IO Not Adjusting for DST?

by brubell on Wed Mar 17, 2021 11:17 am

The timezone is part of the dictionary defined within secrets.py, you'd want to change the timezone from there instead of within the code.py file itself.

Take a look at the "Secrets file setup" step on this page and look at the "timezone" key in the secrets dictionary: https://learn.adafruit.com/magtag-googl ... -3081314-2

brubell
 
Posts: 1377
Joined: Fri Jul 17, 2015 10:33 pm

Re: IO Not Adjusting for DST?

by rspengler on Wed Mar 24, 2021 9:40 am

Thanks brubell. I appreciate the tip. The problem is the code is set to modify the datetime value to match the requirement for the Google Calendar API, which requires an explicit timezone designation on the end (e.g. -4:00 for EDT). The issue arises during the change from standard time to daylight savings time, or vice versa, when the timezone goes from -5 UTC to -4 UTC. This can't be easily resolved via the options available from what I can tell, but I haven't spent a ton of time on it yet.

I get the right time based on what I input into the secrets file, but the code at line 81 on https://learn.adafruit.com/magtag-google-calendar-event-display/code-usage doesn't account for this twice a year change in the offset from UTC.

rspengler
 
Posts: 3
Joined: Mon Jan 11, 2021 11:22 pm

Re: IO Not Adjusting for DST?

by brubell on Wed Mar 24, 2021 10:32 am

The magtag.get_local_time(secrets["timezone"]) call within the code fetches the tz info from Adafruit IO and handles datetime/DST parsing from the server-side. I don't understand why the code wouldn't account for this change?

brubell
 
Posts: 1377
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.