diff --git a/library.properties b/library.properties index 121ff76..3dff520 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Timezone -version=1.2.0 +version=1.2.1 author=Jack Christensen maintainer=Jack Christensen sentence=Arduino library to facilitate time zone conversions and automatic daylight saving (summer) time adjustments. diff --git a/src/Timezone.cpp b/src/Timezone.cpp index 77b291d..fbf4fdf 100644 --- a/src/Timezone.cpp +++ b/src/Timezone.cpp @@ -16,14 +16,20 @@ * Create a Timezone object from the given time change rules. * *----------------------------------------------------------------------*/ Timezone::Timezone(TimeChangeRule dstStart, TimeChangeRule stdStart) - : m_dst(dstStart), m_std(stdStart), m_dstUTC(0), m_stdUTC(0), m_dstLoc(0), m_stdLoc(0) {} + : m_dst(dstStart), m_std(stdStart) +{ + initTimeChanges(); +} /*----------------------------------------------------------------------* * Create a Timezone object for a zone that does not observe * * daylight time. * *----------------------------------------------------------------------*/ Timezone::Timezone(TimeChangeRule stdTime) - : m_dst(stdTime), m_std(stdTime), m_dstUTC(0), m_stdUTC(0), m_dstLoc(0), m_stdLoc(0) {} + : m_dst(stdTime), m_std(stdTime) +{ + initTimeChanges(); +} #ifdef __AVR__ /*----------------------------------------------------------------------* @@ -154,6 +160,17 @@ void Timezone::calcTimeChanges(int yr) m_stdUTC = m_stdLoc - m_dst.offset * SECS_PER_MIN; } +/*----------------------------------------------------------------------* + * Initialize the DST and standard time change points. * + *----------------------------------------------------------------------*/ +void Timezone::initTimeChanges() +{ + m_dstLoc = 0; + m_stdLoc = 0; + m_dstUTC = 0; + m_stdUTC = 0; +} + /*----------------------------------------------------------------------* * Convert the given time change rule to a time_t value * * for the given year. * @@ -196,10 +213,7 @@ void Timezone::setRules(TimeChangeRule dstStart, TimeChangeRule stdStart) { m_dst = dstStart; m_std = stdStart; - m_dstUTC = 0; // force calcTimeChanges() at next conversion call - m_stdUTC = 0; - m_dstLoc = 0; - m_stdLoc = 0; + initTimeChanges(); // force calcTimeChanges() at next conversion call } #ifdef __AVR__ @@ -212,10 +226,7 @@ void Timezone::readRules(int address) eeprom_read_block((void *) &m_dst, (void *) address, sizeof(m_dst)); address += sizeof(m_dst); eeprom_read_block((void *) &m_std, (void *) address, sizeof(m_std)); - m_dstUTC = 0; // force calcTimeChanges() at next conversion call - m_stdUTC = 0; - m_dstLoc = 0; - m_stdLoc = 0; + initTimeChanges(); // force calcTimeChanges() at next conversion call } /*----------------------------------------------------------------------* diff --git a/src/Timezone.h b/src/Timezone.h index 337516e..8d353ec 100644 --- a/src/Timezone.h +++ b/src/Timezone.h @@ -49,6 +49,7 @@ class Timezone private: void calcTimeChanges(int yr); + void initTimeChanges(); time_t toTime_t(TimeChangeRule r, int yr); TimeChangeRule m_dst; // rule for start of dst or summer time for any year TimeChangeRule m_std; // rule for start of standard time for any year