Timezone Library

I'm attempting to make use of this time zone library.


The example sketch sets up a software RTC based on the compile time; all this works great in theory. I have a chronodot RTC attached to the arduino functioning as expected. I can not seem to make the timezone library accept the time from the RTC instead of the compile time. If anyone has any input I would appreciate it.


I set the examples up that way rather than assume the user had any specific hardware connected. Which example sketch are you using?

Here is a modification of the “Clock” example sketch. Please give it a try and let me know if it works for you, and I’ll include it as another example in the Library.

Basically, the “Clock” example includes a function compileTime() which is called from setup() to set the time. That call needs to be deleted, and replaced by a call to setSyncProvider() which will cause the Time library to synchronize with the RTC. Also see the “TimeRTC” example sketch that comes with the Time library.

HTH … jc

 * Timezone library example sketch.                                     *
 * Self-adjusting clock for one time zone using an external real-time   *
 * clock, either a DS1307 or DS3231 (e.g. Chronodot).                   *
 * Assumes the RTC is set to UTC.                                       *
 * TimeChangeRules can be hard-coded or read from EEPROM, see comments. *
 * Check out the Chronodot at http://www.macetech.com/store/            *
 *                                                                      *
 * Jack Christensen Aug 2012                                            *
 *                                                                      *
 * This work is licensed under the Creative Commons Attribution-        *
 * ShareAlike 3.0 Unported License. To view a copy of this license,     *
 * visit http://creativecommons.org/licenses/by-sa/3.0/ or send a       *
 * letter to Creative Commons, 171 Second Street, Suite 300,            *
 * San Francisco, California, 94105, USA.                               *

#include <DS1307RTC.h>   //http://www.arduino.cc/playground/Code/Time
#include <Time.h>        //http://www.arduino.cc/playground/Code/Time
#include <Timezone.h>    //https://github.com/JChristensen/Timezone
#include <Wire.h>        //http://arduino.cc/en/Reference/Wire (supplied with the Arduino IDE)

//US Eastern Time Zone (New York, Detroit)
TimeChangeRule myDST = {"EDT", Second, Sun, Mar, 2, -240};    //Daylight time = UTC - 4 hours
TimeChangeRule mySTD = {"EST", First, Sun, Nov, 2, -300};     //Standard time = UTC - 5 hours
Timezone myTZ(myDST, mySTD);

//If TimeChangeRules are already stored in EEPROM, comment out the three
//lines above and uncomment the line below.
//Timezone myTZ(100);       //assumes rules stored at EEPROM address 100

TimeChangeRule *tcr;        //pointer to the time change rule, use to get TZ abbrev
time_t utc, local;

void setup(void)
    setSyncProvider(RTC.get);   // the function to get the time from the RTC
    if(timeStatus()!= timeSet) 
        Serial.println("Unable to sync with the RTC");
        Serial.println("RTC has set the system time");      

void loop(void)
    utc = now();
    printTime(utc, "UTC");
    local = myTZ.toLocal(utc, &tcr);
    printTime(local, tcr -> abbrev);

//Function to print time with time zone
void printTime(time_t t, char *tz)
    Serial.print(' ');
    Serial.print(' ');
    Serial.print(' ');
    Serial.print(' ');
    Serial.print(' ');

//Print an integer in "00" format (with leading zero).
//Input value assumed to be between 0 and 99.
void sPrintI00(int val)
    if (val < 10) Serial.print('0');
    Serial.print(val, DEC);

//Print an integer in ":00" format (with leading zero).
//Input value assumed to be between 0 and 99.
void sPrintDigits(int val)
    if(val < 10) Serial.print('0');
    Serial.print(val, DEC);

Hey Jack,

Never test for an error condition you don't know how to handle.

Like that.. My favorite, "There is nothing more catastrophic than a successful retry of the WRONG operation" (From the IBM Series/1 designers's handbook, about 1975).

Hey Jack,

Never test for an error condition you don’t know how to handle.

Like that… My favorite, “There is nothing more catastrophic than a successful retry of the WRONG operation” (From the IBM Series/1 designers’s handbook, about 1975).

Hey Terry!

You’ve been scarce? Anyhoo that quote’s not original, wish I could remember where it came from. I remember the S/1, never worked on them, but we had some around. That’s a good quote too, nothing can create havoc faster than a computer doing the wrong thing! The RBS Group banks recently learned that one the hard way: http://spectrum.ieee.org/riskfactor/computing/it/rbs-group-banking-nightmare-continues-for-some

I've been experimenting with the clock example.

I've got a number of LCD screen's spread throughout the office building I work in attached to 2 arduino ethernet. During the day the screens display general info such as temp, humidity, and hopefully time and date.

The RTC is set to UTC for logging purposes (and the fact I don't want the headache of dealing with DST).

Thanks so much, I'll give that a try when I get to work tomorrow.

In function `setup':
*.cpp:44: undefined reference to `DS1307RTC::get()'
*.cpp:44: undefined reference to `DS1307RTC::get()'

I'm getting the above error while trying to compile, the relevant libraires are the newest versions available.

Well, it was a conflict in my library folder that caused the error. The sketch works as expected once loaded.

Thanks for producing this library, saves me a bunch of headaches.

Good deal! Glad you like the library.