Timezone - Programmatically create a TimeChangeRule from variables

Hi All,

I am trying to use the Timezone library. I have a list of time zones in a file stored on an SD card on MKRZero. I have the user select the required time zone from a dropdown on the webpage. That all works, and i can retrieve the variables from the entry that are required to generate the TimeChangeRule JSON, but for the life of me I can workout how to create the TimeChangeRule.

I tried passing it the variables as String and as char arrays but it wont accept them.

TimeChangeRule myDST = {tzNameString , tzWOMString , tzDOWString , tzHOURString , tzOffSetString};
TimeChangeRule mySTD = {tzNameString , tzCharWOM , tzCharDOW , tzCharHOUR , tzCharOffSet};

I get "cannot convert 'arduino::String' to 'char' in initialization" when using string and "invalid conversion from 'char*' to 'char' [-fpermissive]" when using char.

I come from an old school code background of VB so String I understand, I am starting to get to grips with char arrays but I am stuck on this and have no idea what the TimeChangeRule is expecting or how to find out.

Has anyone done this and is able to point me in the right direction? The MKRZero has a reasonable amount of program space, so I could use a huge if else block to create them, but I am trying to avoid that so that if the DST values change, I can upload a new TZ file.

Thanks
Ian...

From an example with the library, it appears that TimeChangeRule uses the following format

TimeChangeRule dstRule = {"EDT", Second, Sun, Mar, 2, -240};

From the library .h file the parameter types are as follows

struct TimeChangeRule
{
    char abbrev[6];    // five chars max
    uint8_t week;      // First, Second, Third, Fourth, or Last week of the month
    uint8_t dow;       // day of week, 1=Sun, 2=Mon, ... 7=Sat
    uint8_t month;     // 1=Jan, 2=Feb, ... 12=Dec
    uint8_t hour;      // 0-23
    int offset;        // offset from UTC in minutes
};

From this you can see the data types required and only the first one is a string or a string constant not a String

NOTE : I do not have the library installed and I am going on what I can see in the library on GitHub

Thanks for the reply, I will have another look at creating the variables with the correct types.

Thanks
Ian...

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.