Skip to content

Commit 265ce38

Browse files
committed
Add support for fractional time zone offsets
1 parent f04b614 commit 265ce38

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

Firmware/OpenLog_Artemis/menuTimeStamp.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void menuTimeStamp()
152152
else if (incoming == 9)
153153
{
154154
SerialPrint(F("Enter the local hour offset from UTC (-12 to 14): "));
155-
int offset = getNumber(menuTimeout); //Timeout after x seconds
155+
float offset = (float)getDouble(menuTimeout); //Timeout after x seconds
156156
if (offset < -12 || offset > 14)
157157
SerialPrintln(F("Error: Offset is out of range"));
158158
else

Firmware/OpenLog_Artemis/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ struct struct_settings {
374374
bool logA13 = false;
375375
bool logA32 = false;
376376
bool logAnalogVoltages = true;
377-
int localUTCOffset = 0; //Default to UTC because we should
377+
float localUTCOffset = 0; // Default to UTC because we should. Support offsets in 15 minute increments.
378378
bool printDebugMessages = false;
379379
#if(HARDWARE_VERSION_MAJOR == 0)
380380
bool powerDownQwiicBusBetweenReads = false; // For the SparkX (black) board: default to leaving the Qwiic power enabled during sleep and powerDown to prevent a brown-out.

Firmware/OpenLog_Artemis/timeStamp.ino

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ void getTimeString(char timeStringBuffer[])
4949
char rtcMin[3];
5050
char rtcSec[3];
5151
char rtcHundredths[3];
52-
char timeZone[4];
52+
char timeZoneH[4];
53+
char timeZoneM[4];
5354
if (adjustedHour < 10)
5455
sprintf(rtcHour, "0%d", adjustedHour);
5556
else
@@ -69,20 +70,27 @@ void getTimeString(char timeStringBuffer[])
6970
if (settings.localUTCOffset >= 0)
7071
{
7172
if (settings.localUTCOffset < 10)
72-
sprintf(timeZone, "+0%d", settings.localUTCOffset);
73+
sprintf(timeZoneH, "+0%d", (int)settings.localUTCOffset);
7374
else
74-
sprintf(timeZone, "+%d", settings.localUTCOffset);
75+
sprintf(timeZoneH, "+%d", (int)settings.localUTCOffset);
7576
}
7677
else
7778
{
7879
if (settings.localUTCOffset <= -10)
79-
sprintf(timeZone, "-%d", 0 - settings.localUTCOffset);
80+
sprintf(timeZoneH, "-%d", 0 - (int)settings.localUTCOffset);
8081
else
81-
sprintf(timeZone, "-0%d", 0 - settings.localUTCOffset);
82+
sprintf(timeZoneH, "-0%d", 0 - (int)settings.localUTCOffset);
8283
}
84+
int tzMins = (int)((settings.localUTCOffset - (float)((int)settings.localUTCOffset)) * 60.0);
85+
if (tzMins < 0)
86+
tzMins = 0 - tzMins;
87+
if (tzMins < 10)
88+
sprintf(timeZoneM, ":0%d", tzMins);
89+
else
90+
sprintf(timeZoneM, ":%d", tzMins);
8391
if ((settings.logDate) && (settings.dateStyle == 3))
8492
{
85-
sprintf(rtcTime, "%s:%s:%s%s:00,", rtcHour, rtcMin, rtcSec, timeZone);
93+
sprintf(rtcTime, "%s:%s:%s%s%s,", rtcHour, rtcMin, rtcSec, timeZoneH, timeZoneM);
8694
strcat(timeStringBuffer, rtcTime);
8795
}
8896
if (settings.logTime)
@@ -142,18 +150,32 @@ void getGPSDateTime(int &year, int &month, int &day, int &hour, int &minute, int
142150
//Do it twice - to make sure the data is fresh
143151
getUbloxDateTime(year, month, day, hour, minute, second, millisecond, dateValid, timeValid);
144152

145-
adjustToLocalDateTime(year, month, day, hour, settings.localUTCOffset);
153+
adjustToLocalDateTime(year, month, day, hour, minute, settings.localUTCOffset);
146154
}
147155

148156
//Given the date and hour, calculate local date/time
149157
//Adjust the hour by local hour offset
150158
//Adjust the hour by DST as necessary
151159
//Adjust the date as necessary
152160
//Leap year is taken into account but does not interact with DST (DST happens later in March)
153-
void adjustToLocalDateTime(int &year, int &month, int &day, int &hour, int localUTCOffset) {
161+
void adjustToLocalDateTime(int &year, int &month, int &day, int &hour, int &minute, float localUTCOffset) {
154162

155163
//Apply any offset to UTC
156-
hour += localUTCOffset;
164+
hour += (int)localUTCOffset;
165+
166+
//Apply minutes offset
167+
int tzMins = (int)((localUTCOffset - (float)((int)localUTCOffset)) * 60.0);
168+
minute += tzMins;
169+
if (minute >= 60)
170+
{
171+
hour += 1;
172+
minute -= 60;
173+
}
174+
else if (minute < 0)
175+
{
176+
hour -= 1;
177+
minute += 60;
178+
}
157179

158180
//If the adjusted hour is outside 0 to 23, then adjust date as necessary
159181
correctDate(year, month, day, hour);

0 commit comments

Comments
 (0)