From ed794b921da0e23e660c1fb9fa82a0aee8aeb982 Mon Sep 17 00:00:00 2001 From: MonsterYuan <248655019@qq.com> Date: Fri, 8 Sep 2023 17:15:55 +0800 Subject: [PATCH] fix bugs. --- src/ezTime.cpp | 34 ++++++++++++++++++++++++++++------ src/ezTime.h | 4 ++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/ezTime.cpp b/src/ezTime.cpp index 78d4399..41d26db 100644 --- a/src/ezTime.cpp +++ b/src/ezTime.cpp @@ -602,10 +602,12 @@ time_t Timezone::tzTime(time_t t, ezLocalOrUTC_t local_or_utc, String &tzname, b t = _last_read_t; local_or_utc = UTC_TIME; } - + bool no_dst_time = true; + bool zerolabel=false; + bool zerolabel_dst=false; int8_t offset_hr = 0; uint8_t offset_min = 0; - int8_t dst_shift_hr = 1; + int8_t dst_shift_hr = 0; uint8_t dst_shift_min = 0; uint8_t start_month = 0, start_week = 0, start_dow = 0, start_time_hr = 2, start_time_min = 0; @@ -631,6 +633,9 @@ time_t Timezone::tzTime(time_t t, ezLocalOrUTC_t local_or_utc, String &tzname, b if (c == '<') ignore_nums = true; if (c == '>') ignore_nums = false; if (!ignore_nums && (isDigit(c) || c == '-' || c == '+')) { + if(c == '-'){ + zerolabel=true; + } state = OFFSET_HR; stdname_end = strpos - 1; } @@ -665,6 +670,9 @@ time_t Timezone::tzTime(time_t t, ezLocalOrUTC_t local_or_utc, String &tzname, b c = 0; dstname_end = strpos - 1; } else if (!ignore_nums && (c == '-' || isDigit(c))) { + if(c == '-'){ + zerolabel_dst=true; + } state = DST_SHIFT_HR; dstname_end = strpos - 1; } @@ -676,7 +684,10 @@ time_t Timezone::tzTime(time_t t, ezLocalOrUTC_t local_or_utc, String &tzname, b } else if (c == ',') { state = START_MONTH; c = 0; - } else if (dst_shift_hr == 1) dst_shift_hr = atoi(_posix.c_str() + strpos); + } else if((!dst_shift_hr)){ + dst_shift_hr = atoi(_posix.c_str() + strpos); + no_dst_time = false; + } } if (c && state == DST_SHIFT_MIN) { if (c == ',') { @@ -751,15 +762,26 @@ time_t Timezone::tzTime(time_t t, ezLocalOrUTC_t local_or_utc, String &tzname, b } int16_t std_offset = (offset_hr < 0) ? offset_hr * 60 - offset_min : offset_hr * 60 + offset_min; - + if(zerolabel){ + std_offset = offset_hr * 60 - offset_min; + } tzname = _posix.substring(0, stdname_end + 1); // Overwritten with dstname later if needed if (!start_month) { if (tzname == "UTC" && std_offset) tzname = "???"; is_dst = false; offset = std_offset; } else { - int16_t dst_offset = std_offset - dst_shift_hr * 60 - dst_shift_min; - // to find the year + //int16_t dst_offset = std_offset - dst_shift_hr * 60 - dst_shift_min; + int16_t dst_offset = 0; + if(no_dst_time){ + dst_offset = std_offset - 60 ; + }else{ + dst_offset = (dst_shift_hr < 0) ? dst_shift_hr * 60 - dst_shift_min : dst_shift_hr * 60 + dst_shift_min; + if(zerolabel_dst){ + dst_offset = dst_shift_hr * 60 - dst_shift_min; + } + } + // to find the year tmElements_t tm; ezt::breakTime(t, tm); diff --git a/src/ezTime.h b/src/ezTime.h index d849847..4198cb9 100644 --- a/src/ezTime.h +++ b/src/ezTime.h @@ -145,7 +145,7 @@ typedef struct { #define NTP_PACKET_SIZE 48 #define NTP_LOCAL_PORT 4242 #define NTP_SERVER "pool.ntp.org" -#define NTP_TIMEOUT 1500 // milliseconds +#define NTP_TIMEOUT 3000 // milliseconds #define NTP_INTERVAL 1801 // default update interval in seconds #define NTP_RETRY 20 // Retry after this many seconds on failed NTP #define NTP_STALE_AFTER 3602 // If update due for this many seconds, set timeStatus to timeNeedsSync @@ -153,7 +153,7 @@ typedef struct { #define TIMEZONED_REMOTE_HOST "timezoned.rop.nl" #define TIMEZONED_REMOTE_PORT 2342 #define TIMEZONED_LOCAL_PORT 2342 -#define TIMEZONED_TIMEOUT 2000 // milliseconds +#define TIMEZONED_TIMEOUT 5000 // milliseconds #define EEPROM_CACHE_LEN 50 #define MAX_CACHE_PAYLOAD ((EEPROM_CACHE_LEN - 3) / 3) * 4 + ( (EEPROM_CACHE_LEN - 3) % 3) // 2 bytes for len and date, then 4 to 3 (6-bit) compression on rest