Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Timezone lib

  1. #1

    Timezone lib

    Hello,

    I am going to program the change of time for standard time / summer time for France. I found an easy algorithm and I have to code it. Could you confirm it is not already done in the Teensyduino libraries?

    Other question, for testing I change date of my computer to a later date and now I have to stay after this date to compile change in my code. How to purge executable files to force recompile the code at the date of today?
    When I program a Teensy 3 with RTC feature for the first time, it take automatically the local time of the Linux host computer. Is there a way to change it by the UTC time without recompiling the Teensyduino toolchain? I ask to avoid to send the T+timestamp message...

    With best regards,
    Thanks in advance,
    Vincent

    EDIT: add piece of code :
    #include <TimeLib.h>
    #define MARCH 3
    #define OCTOBER 10
    void setup() {
    setup_rtc();
    time_t t_utc, t_loc, t;
    char m;
    int tmp, k, y, d;
    char isSummerTime = false;
    for (int j = 0; j <= 366 * 5; j++) {
    update_rtc();
    t_utc = now();
    t_utc += 3600 * 24 * j;
    t = t_utc;
    m = month(t);
    if (m < MARCH || m > OCTOBER) isSummerTime = false;
    else if (m > MARCH && m < OCTOBER) isSummerTime = true;
    else if (m == MARCH) {
    //compute date of the change to Summer
    k = ((497 * (year(t) - 2000)) / 400);
    if (year(t) % 4 == 0) k++;
    d = 31 - (5 + k) % 7;
    if (day(t) < d) isSummerTime = false;
    else isSummerTime = true;
    } else { // (m == OCTOBER)
    //compute date of the change to Winter
    k = ((497 * (year(t) - 2000)) / 400);
    if (year(t) % 4 == 0) k++;
    d = 31 - (2 + k) % 7;
    if (day(t) >= d) isSummerTime = false;
    else isSummerTime = true;
    }
    if (isSummerTime) t_loc = t_utc + 7200; // +2H00
    else t_loc = t_utc + 3600; // +1H00
    if (day(t) == d) {
    if (isSummerTime) Serial.print(">> ");
    else Serial.print("<< ");
    Serial.print(hour(t));
    printDigits(minute(t));
    printDigits(second(t));
    Serial.print(" ");
    Serial.print(day(t));
    Serial.print(" ");
    Serial.print(month(t));
    Serial.print(" ");
    Serial.print(year(t));
    Serial.print(" UTC - ");
    Serial.print(hour(t_loc));
    printDigits(minute(t_loc));
    printDigits(second(t_loc));
    Serial.print(" ");
    Serial.print(day(t_loc));
    Serial.print(" ");
    Serial.print(month(t_loc));
    Serial.print(" ");
    Serial.print(year(t_loc));
    if (isSummerTime) Serial.println(" FR SUMMER");
    else Serial.println(" FR WINTER");
    }
    }
    }
    Last edited by Vincenet; 01-18-2017 at 06:39 PM. Reason: add piece of code

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,513
    Hi Vincenet,

    I am also wondering about Timezone stuff. That is for my well monitor program if I am displaying the data/time from RTC, would be nice to display the data in my appropriate Timezone.

    I was looking around and found the library: https://github.com/JChristensen/Timezone

    That I thought I might take a look at. Not sure what others are using to convert Dates and Times.

    Kurt

  3. #3
    Senior Member Epyon's Avatar
    Join Date
    Apr 2013
    Location
    Belgium
    Posts
    443
    I've used the Timezone lib from JChistensen for a period of time. It's an excellent lib, expect for the issue that the timezone must be specified at compile time. For me this was breaking, because I wanted my devices to be field-commissioned and not precommissioned. I ended up just using UTC and Unix time, which is what you get from timesync services as ntp, cellular or GPS.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •