Skip to content

Commit

Permalink
Add function to initialize time change point member variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
JChristensen committed Sep 26, 2018
1 parent 05bddde commit 3699124
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Timezone
version=1.2.0
version=1.2.1
author=Jack Christensen <[email protected]>
maintainer=Jack Christensen <[email protected]>
sentence=Arduino library to facilitate time zone conversions and automatic daylight saving (summer) time adjustments.
Expand Down
31 changes: 21 additions & 10 deletions src/Timezone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__
/*----------------------------------------------------------------------*
Expand Down Expand Up @@ -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. *
Expand Down Expand Up @@ -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__
Expand All @@ -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
}

/*----------------------------------------------------------------------*
Expand Down
1 change: 1 addition & 0 deletions src/Timezone.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3699124

Please sign in to comment.