Skip to content

Commit

Permalink
src: Remove TimeOffset::toOffsetCode(), everything now uses toMinutes…
Browse files Browse the repository at this point in the history
…() (#18)
  • Loading branch information
bxparks committed Aug 15, 2019
1 parent f864f96 commit 298fe3a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 34 deletions.
10 changes: 4 additions & 6 deletions examples/CommandLineClock/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ class Controller {
SERIAL_PORT_MONITOR.println(F("preserveInfo()"));
mIsStoredInfoValid = true;
mStoredInfo.timeZoneType = mTimeZone.getType();
mStoredInfo.stdOffsetCode =
mTimeZone.getStdOffset().toOffsetCode();
mStoredInfo.dstOffsetCode =
mTimeZone.getDstOffset().toOffsetCode();
mStoredInfo.stdMinutes = mTimeZone.getStdOffset().toMinutes();
mStoredInfo.dstMinutes = mTimeZone.getDstOffset().toMinutes();
mStoredInfo.zoneId = mTimeZone.getZoneId();
return mPersistentStore.writeStoredInfo(mStoredInfo);
}
Expand All @@ -200,8 +198,8 @@ class Controller {
break;
case TimeZone::kTypeManual:
setManualTimeZone(
TimeOffset::forOffsetCode(storedInfo.stdOffsetCode),
TimeOffset::forOffsetCode(storedInfo.dstOffsetCode));
TimeOffset::forMinutes(storedInfo.stdMinutes),
TimeOffset::forMinutes(storedInfo.dstMinutes));
break;
default:
SERIAL_PORT_MONITOR.print(F("restoreInfo(): Setting UTC timezone"));
Expand Down
8 changes: 4 additions & 4 deletions examples/CommandLineClock/StoredInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ struct StoredInfo {
/** Time zone of the displayed time */
uint8_t timeZoneType;

/** The offset code for kTypeManual. */
int8_t stdOffsetCode;
/** The STD offset for kTypeManual. */
int16_t stdMinutes;

/** The DST offset code for kTypeManual. */
int8_t dstOffsetCode;
/** The DST offset for kTypeManual. */
int16_t dstMinutes;

/**
* Stable zone ID for kTypeBasic, kTypeExtended, kTypeBasicManaged,
Expand Down
32 changes: 16 additions & 16 deletions examples/OledClock/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,19 @@ class Controller {
case MODE_CHANGE_TIME_ZONE_OFFSET:
{
mSuppressBlink = true;
auto offset = TimeOffset::forOffsetCode(
mChangingClockInfo.timeZone.getStdOffsetCode());
TimeOffset offset = mChangingClockInfo.timeZone.getStdOffset();
time_offset_mutation::increment15Minutes(offset);
mChangingClockInfo.timeZone.setStdOffset(offset);
break;
}
case MODE_CHANGE_TIME_ZONE_DST:
{
mSuppressBlink = true;
uint8_t offsetCode = mChangingClockInfo.timeZone.getDstOffsetCode();
offsetCode = (offsetCode == 0)
? TimeOffset::forMinutes(kDstOffsetMinutes).toOffsetCode()
: 0;
mChangingClockInfo.timeZone.setDstOffset(
TimeOffset::forOffsetCode(offsetCode));
TimeOffset dstOffset = mChangingClockInfo.timeZone.getDstOffset();
dstOffset = (dstOffset.isZero())
? TimeOffset::forMinutes(kDstOffsetMinutes)
: TimeOffset();
mChangingClockInfo.timeZone.setDstOffset(dstOffset);
break;
}

Expand Down Expand Up @@ -381,11 +379,14 @@ class Controller {
SERIAL_PORT_MONITOR.print(F("type: ")); SERIAL_PORT_MONITOR.println(storedInfo.timeZoneData.type);
if (storedInfo.type == TimeZoneData::kTypeManual) {
SERIAL_PORT_MONITOR.print(F("std: "));
SERIAL_PORT_MONITOR.println(storedInfo.timeZoneData.stdOffsetCode);
storedInfo.timeZoneData.stdOffset.printTo(SERIAL_PORT_MONITOR);
SERIAL_PORT_MONITOR.println();
SERIAL_PORT_MONITOR.print(F("dst: "));
SERIAL_PORT_MONITOR.println(storedInfo.timeZoneData.dstOffsetCode);
storedInfo.timeZoneData.dstOffset.printTo(SERIAL_PORT_MONITOR);
SERIAL_PORT_MONITOR.println();
} else if (storedInfo.type == TimeZoneData::kTypeZoneId) {
SERIAL_PORT_MONITOR.print(F("zoneId: 0x")); SERIAL_PORT_MONITOR.println(storedInfo.zoneId, 16);
SERIAL_PORT_MONITOR.print(F("zoneId: 0x"));
SERIAL_PORT_MONITOR.println(storedInfo.zoneId, 16);
} else {
SERIAL_PORT_MONITOR.println(F("<error>"));
}
Expand All @@ -395,8 +396,8 @@ class Controller {
#if TIME_ZONE_TYPE == TIME_ZONE_TYPE_MANUAL
if (storedInfo.timeZoneData.type == TimeZoneData::kTypeManual) {
clockInfo.timeZone = TimeZone::forTimeOffset(
TimeOffset::forOffsetCode(storedInfo.stdOffsetCode),
TimeOffset::forOffsetCode(storedInfo.dstOffsetCode));
TimeOffset::forMinutes(storedInfo.timeZoneData.stdOffsetMinutes),
TimeOffset::forMinutes(storedInfo.timeZoneData.dstOffsetMinutes));
} else {
clockInfo.timeZone = TimeZone::forTimeOffset(
TimeOffset::forMinutes(kDefaultOffsetMinutes),
Expand Down Expand Up @@ -429,9 +430,8 @@ class Controller {

#if TIME_ZONE_TYPE == TIME_ZONE_TYPE_MANUAL
storedInfo.timeZoneData.type = TimeZone::kTypeManual;
storedInfo.timeZoneData.stdOffsetCode =
TimeOffset::forMinues(kDefaultOffsetMinutes).toOffsetCode();
storedInfo.timeZoneData.dstOffsetCode = 0;
storedInfo.timeZoneData.stdOffsetMinutes = kDefaultOffsetMinutes;
storedInfo.timeZoneData.dstOffsetMinutes = 0;
#elif TIME_ZONE_TYPE == TIME_ZONE_TYPE_BASIC
storedInfo.timeZoneData.type = TimeZoneData::kTypeZoneId;
storedInfo.timeZoneData.zoneId =
Expand Down
4 changes: 2 additions & 2 deletions examples/OledClock/Presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ class Presenter {
mOled.println();
mOled.print("UTC");
if (shouldShowFor(MODE_CHANGE_TIME_ZONE_OFFSET)) {
auto offset = TimeOffset::forOffsetCode(tz.getStdOffsetCode());
TimeOffset offset = tz.getStdOffset();
offset.printTo(mOled);
}
mOled.clearToEOL();

mOled.println();
mOled.print("DST: ");
if (shouldShowFor(MODE_CHANGE_TIME_ZONE_DST)) {
mOled.print((tz.getDstOffsetCode() != 0) ? "on " : "off");
mOled.print((tz.getDstOffset().isZero()) ? "off " : "on");
}
mOled.clearToEOL();
break;
Expand Down
2 changes: 1 addition & 1 deletion src/ace_time/BasicZoneProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class BasicZoneProcessor: public ZoneProcessor {

// If offset1 and offset2 are equal, then we have an equilibrium
// and odt(1) must equal odt(2), so we can just return the last odt.
if (offset1.toOffsetCode() == offset2.toOffsetCode()) {
if (offset1 == offset2) {
// pass
} else {
// Pick the later epochSeconds and offset
Expand Down
3 changes: 0 additions & 3 deletions src/ace_time/TimeOffset.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ class TimeOffset {
/** Constructor. Create a time offset of 0. */
explicit TimeOffset() {}

/** Return the time offset as the number of 15 minute increments. */
int8_t toOffsetCode() const { return mMinutes / 15; }

/** Return the time offset as minutes. */
int16_t toMinutes() const {
return mMinutes;
Expand Down
8 changes: 6 additions & 2 deletions tests/TimeOffsetTest/TimeOffsetTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ using namespace ace_time;
// TimeOffset
// --------------------------------------------------------------------------

test(TimeOffsetTest, code) {
assertEqual(TimeOffset::forHours(-8).toOffsetCode(), -8*4);
test(TimeOffsetTest, operatorEqualEqual) {
TimeOffset a = TimeOffset::forMinutes(10);
TimeOffset aa = TimeOffset::forMinutes(10);
TimeOffset b = TimeOffset::forMinutes(11);
assertTrue(a == aa);
assertTrue(a != b);
}

test(TimeOffsetTest, isZero) {
Expand Down

0 comments on commit 298fe3a

Please sign in to comment.