Merge pull request #71 from johnslemmer/fixes

Fixes for #69 #70
pull/78/head
Rop Gonggrijp 6 years ago committed by GitHub
commit ddb5c4575b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -749,34 +749,33 @@ time_t Timezone::tzTime(time_t t, ezLocalOrUTC_t local_or_utc, String &tzname, b
if (tzname == "UTC" && std_offset) tzname = "???"; if (tzname == "UTC" && std_offset) tzname = "???";
is_dst = false; is_dst = false;
offset = std_offset; offset = std_offset;
return t - std_offset * 60; } 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; tmElements_t tm;
// to find the year ezt::breakTime(t, tm);
tmElements_t tm;
ezt::breakTime(t, tm);
// in local time // in local time
time_t dst_start = ezt::makeOrdinalTime(start_time_hr, start_time_min, 0, start_week, start_dow + 1, start_month, tm.Year + 1970); time_t dst_start = ezt::makeOrdinalTime(start_time_hr, start_time_min, 0, start_week, start_dow + 1, start_month, tm.Year + 1970);
time_t dst_end = ezt::makeOrdinalTime(end_time_hr, end_time_min, 0, end_week, end_dow + 1, end_month, tm.Year + 1970); time_t dst_end = ezt::makeOrdinalTime(end_time_hr, end_time_min, 0, end_week, end_dow + 1, end_month, tm.Year + 1970);
if (local_or_utc == UTC_TIME) { if (local_or_utc == UTC_TIME) {
dst_start += std_offset * 60LL; dst_start += std_offset * 60LL;
dst_end += dst_offset * 60LL; dst_end += dst_offset * 60LL;
} }
if (dst_end > dst_start) { if (dst_end > dst_start) {
is_dst = (t >= dst_start && t < dst_end); // northern hemisphere is_dst = (t >= dst_start && t < dst_end); // northern hemisphere
} else { } else {
is_dst = !(t >= dst_end && t < dst_start); // southern hemisphere is_dst = !(t >= dst_end && t < dst_start); // southern hemisphere
} }
if (is_dst) { if (is_dst) {
offset = dst_offset; offset = dst_offset;
tzname = _posix.substring(dstname_begin, dstname_end + 1); tzname = _posix.substring(dstname_begin, dstname_end + 1);
} else { } else {
offset = std_offset; offset = std_offset;
}
} }
if (local_or_utc == LOCAL_TIME) { if (local_or_utc == LOCAL_TIME) {
@ -1184,7 +1183,18 @@ String Timezone::dateTime(time_t t, const ezLocalOrUTC_t local_or_utc, const Str
String tzname; String tzname;
bool is_dst; bool is_dst;
int16_t offset; int16_t offset;
t = tzTime(t, LOCAL_TIME, tzname, is_dst, offset);
if (t == TIME_NOW || t == LAST_READ || local_or_utc == UTC_TIME) {
// in these cases we actually want tzTime to translate the time for us
// back in to this timezone's time as well as grab the timezone info
// from the stored POSIX data
t = tzTime(t, UTC_TIME, tzname, is_dst, offset);
} else {
// when receiving a local time we don't want to translate the timestamp
// but rather use tzTime to just parse the info about the timezone from
// the stored POSIX data
tzTime(t, LOCAL_TIME, tzname, is_dst, offset);
}
String tmpstr; String tmpstr;
uint8_t tmpint8; uint8_t tmpint8;

Loading…
Cancel
Save