Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DST timezone error fix #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/ezTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 == ',') {
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/ezTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ 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

#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
Expand Down