Skip to content

Commit

Permalink
Merge pull request G6EJD#168 from skiphansen/fix_forecast_timezone_adj
Browse files Browse the repository at this point in the history
Fix UTC to local time conversion error in DisplayForecastWeather for …
  • Loading branch information
G6EJD authored Dec 9, 2021
2 parents f09b7ad + fc8888a commit 081decb
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 33 deletions.
10 changes: 5 additions & 5 deletions Waveshare_2_9_v4.ino
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void DisplayWeather() { // 2.9" e-paper display is 296x128 resolutio
String MidTime = "09:00" + String((Units == "M" ? "" : "a"));
String FinishTime = "10:00" + String((Units == "M" ? "" : "a"));
do {
String Ftime = ConvertUnixTime(WxForecast[Forecast].Dt).substring(0, (Units == "M" ? 5 : 6));
String Ftime = ConvertUnixTime(WxForecast[Forecast].Dt + WxForecast[Forecast].Timezone).substring(0, (Units == "M" ? 5 : 6));
if (Ftime == StartTime || Ftime == MidTime || Ftime == FinishTime) {
DisplayForecastWeather(18, 104, Forecast, Dposition, 57); // x,y coordinates, forecast number, position, spacing width
Dposition++;
Expand Down Expand Up @@ -216,9 +216,9 @@ void DisplayAstronomySection(int x, int y) {
display.drawRect(x, y + 13, 126, 51, GxEPD_BLACK);
u8g2Fonts.setFont(u8g2_font_helvB08_tf);
SunRise(x + 64, y + 23);
drawString(x + 80, y + 20, ConvertUnixTime(WxConditions[0].Sunrise).substring(0, (Units == "M" ? 5 : 7)), LEFT);
drawString(x + 80, y + 20, ConvertUnixTime(WxConditions[0].Sunrise + WxConditions[0].Timezone).substring(0, (Units == "M" ? 5 : 7)), LEFT);
SunSet(x + 64, y + 38);
drawString(x + 80, y + 35, ConvertUnixTime(WxConditions[0].Sunset).substring(0, (Units == "M" ? 5 : 7)), LEFT);
drawString(x + 80, y + 35, ConvertUnixTime(WxConditions[0].Sunset + WxConditions[0].Timezone).substring(0, (Units == "M" ? 5 : 7)), LEFT);
time_t now = time(NULL);
struct tm * now_utc = gmtime(&now);
const int day_utc = now_utc->tm_mday;
Expand Down Expand Up @@ -392,8 +392,8 @@ void GetHighsandLows() {
String StartTime = "08:00" + String((Units == "M" ? "" : "a"));
String FinishTime = "10:00" + String((Units == "M" ? "" : "a"));
for (int r = 0; r < max_readings; r++) {
if (ConvertUnixTime(WxForecast[r].Dt).substring(0, (Units == "M" ? 5 : 6)) >= StartTime && ConvertUnixTime(WxForecast[r].Dt).substring(0, (Units == "M" ? 5 : 6)) <= FinishTime) { // found first period in day
HLReadings[Day].Time = ConvertUnixTime(WxForecast[r].Dt).substring(0, (Units == "M" ? 5 : 6));
if (ConvertUnixTime(WxForecast[r].Dt + WxForecast[r].Timezone).substring(0, (Units == "M" ? 5 : 6)) >= StartTime && ConvertUnixTime(WxForecast[r].Dt + WxForecast[r].Timezone).substring(0, (Units == "M" ? 5 : 6)) <= FinishTime) { // found first period in day
HLReadings[Day].Time = ConvertUnixTime(WxForecast[r].Dt + WxForecast[r].Timezone).substring(0, (Units == "M" ? 5 : 6));
for (int InDay = 0; InDay < 8; InDay++) { // 00:00 to 21:00 is 8 readings
if (r + InDay < max_readings) {
if (WxForecast[r + InDay].High > HLReadings[Day].High) {
Expand Down
2 changes: 1 addition & 1 deletion examples/M5_CoreInk/M5_CoreInk.ino
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void DisplayForecastWeather(int x, int y, int offset, int index) {
display.drawRect(x, y, offset, 65, GxEPD_BLACK);
display.drawLine(x, y + 13, x + offset, y + 13, GxEPD_BLACK);
DisplayWxIcon(x + offset / 2 + 1, y + 35, WxForecast[index].Icon, SmallIcon);
drawString(x + offset / 2, y + 3, String(ConvertUnixTime(WxForecast[index].Dt + WxConditions[0].Timezone).substring(0,5)), CENTER);
drawString(x + offset / 2, y + 3, String(ConvertUnixTime(WxForecast[index].Dt + WxForecast[index].Timezone).substring(0,5)), CENTER);
drawString(x + offset / 2, y + 50, String(WxForecast[index].High, 0) + "/" + String(WxForecast[index].Low, 0), CENTER);
}
//#########################################################################################
Expand Down
4 changes: 2 additions & 2 deletions examples/OWM_75_epaper_v16_7/OWM_75_epaper_v16_7.ino
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ void DisplayPrecipitationSection(int x, int y, int pwidth, int pdepth) {
void DisplayAstronomySection(int x, int y) {
display.drawRect(x, y + 13, 173, 52, GxEPD_BLACK);
u8g2Fonts.setFont(u8g2_font_helvR08_tf);
drawString(x + 4, y + 18, ConvertUnixTime(WxConditions[0].Sunrise).substring(0, 5) + " " + TXT_SUNRISE, LEFT);
drawString(x + 4, y + 32, ConvertUnixTime(WxConditions[0].Sunset).substring(0, 5) + " " + TXT_SUNSET, LEFT);
drawString(x + 4, y + 18, ConvertUnixTime(WxConditions[0].Sunrise + WxConditions[0].Timezone).substring(0, 5) + " " + TXT_SUNRISE, LEFT);
drawString(x + 4, y + 32, ConvertUnixTime(WxConditions[0].Sunset + WxConditions[0].Timezone).substring(0, 5) + " " + TXT_SUNSET, LEFT);
time_t now = time(NULL);
struct tm * now_utc = gmtime(&now);
const int day_utc = now_utc->tm_mday;
Expand Down
2 changes: 1 addition & 1 deletion examples/Waveshare_1_54/Waveshare_1_54.ino
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void DisplayForecastWeather(int x, int y, int offset, int index) {
display.drawRect(x, y, offset, 65, GxEPD_BLACK);
display.drawLine(x, y + 13, x + offset, y + 13, GxEPD_BLACK);
DisplayWxIcon(x + offset / 2 + 1, y + 35, WxForecast[index].Icon, SmallIcon);
drawString(x + offset / 2, y + 3, String(ConvertUnixTime(WxForecast[index].Dt + WxConditions[0].Timezone).substring(0,5)), CENTER);
drawString(x + offset / 2, y + 3, String(ConvertUnixTime(WxForecast[index].Dt + WxForecast[index].Timezone).substring(0,5)), CENTER);
drawString(x + offset / 2, y + 50, String(WxForecast[index].High, 0) + "/" + String(WxForecast[index].Low, 0), CENTER);
}
//#########################################################################################
Expand Down
4 changes: 2 additions & 2 deletions examples/Waveshare_2_13_T5/Waveshare_2_13_T5.ino
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ void Draw_3hr_Forecast(int x, int y, int index) {
//#########################################################################################
void DisplayAstronomySection(int x, int y) {
u8g2Fonts.setFont(u8g2_font_helvB08_tf);
drawString(x, y, ConvertUnixTime(WxConditions[0].Sunrise).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNRISE, LEFT);
drawString(x, y + 16, ConvertUnixTime(WxConditions[0].Sunset).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNSET, LEFT);
drawString(x, y, ConvertUnixTime(WxConditions[0].Sunrise + WxConditions[0].Timezone).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNRISE, LEFT);
drawString(x, y + 16, ConvertUnixTime(WxConditions[0].Sunset + WxConditions[0].Timezone).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNSET, LEFT);
time_t now = time(NULL);
struct tm * now_utc = gmtime(&now);
const int day_utc = now_utc->tm_mday;
Expand Down
4 changes: 2 additions & 2 deletions examples/Waveshare_2_7/Waveshare_2_7.ino
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ void DisplayAstronomySection(int x, int y) {
//display.drawLine(x, y + 13, x + 168, y + 13 , GxEPD_BLACK);
display.drawLine(x + 155, y + 13, x + 155, y + 13 + 50, GxEPD_BLACK);
u8g2Fonts.setFont(u8g2_font_helvB08_tf);
drawString(x + 5, y + 18, ConvertUnixTime(WxConditions[0].Sunrise).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNRISE, LEFT);
drawString(x + 5, y + 34, ConvertUnixTime(WxConditions[0].Sunset).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNSET, LEFT);
drawString(x + 5, y + 18, ConvertUnixTime(WxConditions[0].Sunrise + WxConditions[0].Timezone).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNRISE, LEFT);
drawString(x + 5, y + 34, ConvertUnixTime(WxConditions[0].Sunset + WxConditions[0].Timezone).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNSET, LEFT);
time_t now = time(NULL);
struct tm * now_utc = gmtime(&now);
const int day_utc = now_utc->tm_mday;
Expand Down
10 changes: 5 additions & 5 deletions examples/Waveshare_2_9/Waveshare_2_9_v4.ino
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void DisplayWeather() { // 2.9" e-paper display is 296x128 resolutio
String MidTime = "09:00" + String((Units == "M" ? "" : "a"));
String FinishTime = "10:00" + String((Units == "M" ? "" : "a"));
do {
String Ftime = ConvertUnixTime(WxForecast[Forecast].Dt).substring(0, (Units == "M" ? 5 : 6));
String Ftime = ConvertUnixTime(WxForecast[Forecast].Dt + WxForecast[Forecast].Timezone).substring(0, (Units == "M" ? 5 : 6));
if (Ftime == StartTime || Ftime == MidTime || Ftime == FinishTime) {
DisplayForecastWeather(18, 104, Forecast, Dposition, 57); // x,y coordinates, forecast number, position, spacing width
Dposition++;
Expand Down Expand Up @@ -216,9 +216,9 @@ void DisplayAstronomySection(int x, int y) {
display.drawRect(x, y + 13, 126, 51, GxEPD_BLACK);
u8g2Fonts.setFont(u8g2_font_helvB08_tf);
SunRise(x + 64, y + 23);
drawString(x + 80, y + 20, ConvertUnixTime(WxConditions[0].Sunrise).substring(0, (Units == "M" ? 5 : 7)), LEFT);
drawString(x + 80, y + 20, ConvertUnixTime(WxConditions[0].Sunrise + WxConditions[0].Timezone).substring(0, (Units == "M" ? 5 : 7)), LEFT);
SunSet(x + 64, y + 38);
drawString(x + 80, y + 35, ConvertUnixTime(WxConditions[0].Sunset).substring(0, (Units == "M" ? 5 : 7)), LEFT);
drawString(x + 80, y + 35, ConvertUnixTime(WxConditions[0].Sunset + WxConditions[0].Timezone).substring(0, (Units == "M" ? 5 : 7)), LEFT);
time_t now = time(NULL);
struct tm * now_utc = gmtime(&now);
const int day_utc = now_utc->tm_mday;
Expand Down Expand Up @@ -392,8 +392,8 @@ void GetHighsandLows() {
String StartTime = "08:00" + String((Units == "M" ? "" : "a"));
String FinishTime = "10:00" + String((Units == "M" ? "" : "a"));
for (int r = 0; r < max_readings; r++) {
if (ConvertUnixTime(WxForecast[r].Dt).substring(0, (Units == "M" ? 5 : 6)) >= StartTime && ConvertUnixTime(WxForecast[r].Dt).substring(0, (Units == "M" ? 5 : 6)) <= FinishTime) { // found first period in day
HLReadings[Day].Time = ConvertUnixTime(WxForecast[r].Dt).substring(0, (Units == "M" ? 5 : 6));
if (ConvertUnixTime(WxForecast[r].Dt + WxForecast[r].Timezone).substring(0, (Units == "M" ? 5 : 6)) >= StartTime && ConvertUnixTime(WxForecast[r].Dt + WxForecast[r].Timezone).substring(0, (Units == "M" ? 5 : 6)) <= FinishTime) { // found first period in day
HLReadings[Day].Time = ConvertUnixTime(WxForecast[r].Dt + WxForecast[r].Timezone).substring(0, (Units == "M" ? 5 : 6));
for (int InDay = 0; InDay < 8; InDay++) { // 00:00 to 21:00 is 8 readings
if (r + InDay < max_readings) {
if (WxForecast[r + InDay].High > HLReadings[Day].High) {
Expand Down
4 changes: 2 additions & 2 deletions examples/Waveshare_2_9_T5/Waveshare_2_9_T5.ino
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ void Draw_3hr_Forecast(int x, int y, int index) {
void DisplayAstronomySection(int x, int y) {
display.drawRect(x, y + 13, 173, 52, GxEPD_BLACK);
u8g2Fonts.setFont(u8g2_font_helvB08_tf);
drawString(x + 5, y + 18, ConvertUnixTime(WxConditions[0].Sunrise).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNRISE, LEFT);
drawString(x + 5, y + 34, ConvertUnixTime(WxConditions[0].Sunset).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNSET, LEFT);
drawString(x + 5, y + 18, ConvertUnixTime(WxConditions[0].Sunrise + WxConditions[0].Timezone).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNRISE, LEFT);
drawString(x + 5, y + 34, ConvertUnixTime(WxConditions[0].Sunset + WxConditions[0].Timezone).substring(0, (Units == "M"?5:7)) + " " + TXT_SUNSET, LEFT);
time_t now = time(NULL);
struct tm * now_utc = gmtime(&now);
const int day_utc = now_utc->tm_mday;
Expand Down
6 changes: 3 additions & 3 deletions examples/Waveshare_4_2/Waveshare_4_2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void DrawForecastWeather(int x, int y, int index) {
display.drawRect(x, y, 55, 65, GxEPD_BLACK);
display.drawLine(x + 1, y + 13, x + 54, y + 13, GxEPD_BLACK);
DisplayWXicon(x + 28, y + 35, WxForecast[index].Icon, SmallIcon);
drawString(x + 31, y + 3, String(ConvertUnixTime(WxForecast[index].Dt + WxConditions[0].Timezone).substring(0,5)), CENTER);
drawString(x + 31, y + 3, String(ConvertUnixTime(WxForecast[index].Dt + WxForecast[index].Timezone).substring(0,5)), CENTER);
drawString(x + 41, y + 52, String(WxForecast[index].High, 0) + "° / " + String(WxForecast[index].Low, 0) + "°", CENTER);
}
//#########################################################################################
Expand Down Expand Up @@ -310,8 +310,8 @@ void DisplayPrecipitationSection(int x, int y) {
void DrawAstronomySection(int x, int y) {
u8g2Fonts.setFont(u8g2_font_helvB08_tf);
display.drawRect(x, y + 64, 167, 48, GxEPD_BLACK);
drawString(x + 7, y + 70, ConvertUnixTime(WxConditions[0].Sunrise).substring(0, (Units == "M" ? 5 : 7)) + " " + TXT_SUNRISE, LEFT);
drawString(x + 7, y + 85, ConvertUnixTime(WxConditions[0].Sunset).substring(0, (Units == "M" ? 5 : 7)) + " " + TXT_SUNSET, LEFT);
drawString(x + 7, y + 70, ConvertUnixTime(WxConditions[0].Sunrise + WxConditions[0].Timezone).substring(0, (Units == "M" ? 5 : 7)) + " " + TXT_SUNRISE, LEFT);
drawString(x + 7, y + 85, ConvertUnixTime(WxConditions[0].Sunset + WxConditions[0].Timezone).substring(0, (Units == "M" ? 5 : 7)) + " " + TXT_SUNSET, LEFT);
time_t now = time(NULL);
struct tm * now_utc = gmtime(&now);
const int day_utc = now_utc->tm_mday;
Expand Down
6 changes: 3 additions & 3 deletions examples/Waveshare_7_5/Waveshare_7_5.ino
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void DisplayForecastWeather(int x, int y, int index) {
display.drawRect(x, y, fwidth - 1, 65, GxEPD_BLACK);
display.drawLine(x, y + 13, x + fwidth - 3, y + 13, GxEPD_BLACK);
DisplayConditionsSection(x + fwidth / 2, y + 35, WxForecast[index].Icon, SmallIcon);
drawString(x + fwidth / 2, y + 3, String(ConvertUnixTime(WxForecast[index].Dt + WxConditions[0].Timezone).substring(0,5)), CENTER);
drawString(x + fwidth / 2, y + 3, String(ConvertUnixTime(WxForecast[index].Dt + WxForecast[index].Timezone).substring(0,5)), CENTER);
drawString(x + fwidth / 2, y + 53, String(WxForecast[index].High, 0) + "°/" + String(WxForecast[index].Low, 0) + "°", CENTER);
}
//#########################################################################################
Expand Down Expand Up @@ -313,8 +313,8 @@ void DisplayPrecipitationSection(int x, int y, int pwidth, int pdepth) {
void DisplayAstronomySection(int x, int y) {
display.drawRect(x, y + 13, 173, 52, GxEPD_BLACK);
u8g2Fonts.setFont(u8g2_font_helvB08_tf);
drawString(x + 3, y + 18, ConvertUnixTime(WxConditions[0].Sunrise).substring(0, 5) + " " + TXT_SUNRISE, LEFT);
drawString(x + 3, y + 32, ConvertUnixTime(WxConditions[0].Sunset).substring(0, 5) + " " + TXT_SUNSET, LEFT);
drawString(x + 3, y + 18, ConvertUnixTime(WxConditions[0].Sunrise + WxConditions[0].Timezone).substring(0, 5) + " " + TXT_SUNRISE, LEFT);
drawString(x + 3, y + 32, ConvertUnixTime(WxConditions[0].Sunset + WxConditions[0].Timezone).substring(0, 5) + " " + TXT_SUNSET, LEFT);
time_t now = time(NULL);
struct tm * now_utc = gmtime(&now);
const int day_utc = now_utc->tm_mday;
Expand Down
6 changes: 3 additions & 3 deletions examples/Waveshare_7_5_T7/Waveshare_7_5_T7.ino
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void DisplayForecastWeather(int x, int y, int index) {
display.drawRect(x, y, fwidth - 1, 81, GxEPD_BLACK);
display.drawLine(x, y + 16, x + fwidth - 3, y + 16, GxEPD_BLACK);
DisplayConditionsSection(x + fwidth / 2, y + 43, WxForecast[index].Icon, SmallIcon);
drawString(x + fwidth / 2, y + 4, String(ConvertUnixTime(WxForecast[index].Dt + WxConditions[0].Timezone).substring(0,5)), CENTER);
drawString(x + fwidth / 2, y + 4, String(ConvertUnixTime(WxForecast[index].Dt + WxForecast[index].Timezone).substring(0,5)), CENTER);
drawString(x + fwidth / 2 + 12, y + 66, String(WxForecast[index].High, 0) + "°/" + String(WxForecast[index].Low, 0) + "°", CENTER);
}
//#########################################################################################
Expand Down Expand Up @@ -306,8 +306,8 @@ void DisplayPrecipitationSection(int x, int y, int pwidth, int pdepth) {
void DisplayAstronomySection(int x, int y) {
display.drawRect(x, y + 16, 216, 65, GxEPD_BLACK);
u8g2Fonts.setFont(u8g2_font_helvB08_tf);
drawString(x + 4, y + 24, ConvertUnixTime(WxConditions[0].Sunrise).substring(0, 5) + " " + TXT_SUNRISE, LEFT);
drawString(x + 4, y + 44, ConvertUnixTime(WxConditions[0].Sunset).substring(0, 5) + " " + TXT_SUNSET, LEFT);
drawString(x + 4, y + 24, ConvertUnixTime(WxConditions[0].Sunrise + WxConditions[0].Timezone).substring(0, 5) + " " + TXT_SUNRISE, LEFT);
drawString(x + 4, y + 44, ConvertUnixTime(WxConditions[0].Sunset + WxConditions[0].Timezone).substring(0, 5) + " " + TXT_SUNSET, LEFT);
time_t now = time(NULL);
struct tm * now_utc = gmtime(&now);
const int day_utc = now_utc->tm_mday;
Expand Down
6 changes: 3 additions & 3 deletions examples/Waveshare_9_7/Waveshare_9_7.ino
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void DisplayForecastWeather(int x, int y, int index) {
display.drawLine(x, y + 40, x + fwidth - 3, y + 40, GxEPD_BLACK);
DisplayConditionsSection(x + fwidth / 2, y + 90, WxForecast[index].Icon, SmallIcon);
u8g2Fonts.setFont(u8g2_font_helvB14_tf);
drawString(x + fwidth / 2 - 10, y + 20, String(ConvertUnixTime(WxForecast[index].Dt + WxConditions[0].Timezone).substring(0,5)), CENTER);
drawString(x + fwidth / 2 - 10, y + 20, String(ConvertUnixTime(WxForecast[index].Dt + WxForecast[index].Timezone).substring(0,5)), CENTER);
drawString(x + fwidth / 2 + 0, y + 130, String(WxForecast[index].High, 0) + "°/" + String(WxForecast[index].Low, 0) + "°", CENTER);
}
//#########################################################################################
Expand Down Expand Up @@ -397,8 +397,8 @@ void DisplayPrecipitationSection(int x, int y, int pwidth, int pdepth) {
void DisplayAstronomySection(int x, int y) {
display.drawRect(x, y + 20, 365, 110, GxEPD_BLACK);
u8g2Fonts.setFont(u8g2_font_helvB14_tf);
drawString(x + 14, y + 54, ConvertUnixTime(WxConditions[0].Sunrise).substring(0, 5) + " " + TXT_SUNRISE, LEFT);
drawString(x + 14, y + 79, ConvertUnixTime(WxConditions[0].Sunset).substring(0, 5) + " " + TXT_SUNSET, LEFT);
drawString(x + 14, y + 54, ConvertUnixTime(WxConditions[0].Sunrise + WxConditions[0].Timezone).substring(0, 5) + " " + TXT_SUNRISE, LEFT);
drawString(x + 14, y + 79, ConvertUnixTime(WxConditions[0].Sunset + WxConditions[0].Timezone).substring(0, 5) + " " + TXT_SUNSET, LEFT);
time_t now = time(NULL);
struct tm * now_utc = gmtime(&now);
const int day_utc = now_utc->tm_mday;
Expand Down
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool DecodeWeather(WiFiClient& json, String Type) {
String ConvertUnixTime(int unix_time) {
// Returns either '21:12 ' or ' 09:12pm' depending on Units mode
time_t tm = unix_time;
struct tm *now_tm = localtime(&tm);
struct tm *now_tm = gmtime(&tm);
char output[40];
if (Units == "M") {
strftime(output, sizeof(output), "%H:%M %d/%m/%y", now_tm);
Expand Down

0 comments on commit 081decb

Please sign in to comment.