<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">I’m supporting a “port” of the tz code where I’ve selectively embedded pieces of localtime.c into an application , so this may be something I’ve broken, but I’ve looked fairly carefully at my implementation.<div class=""><br class=""></div><div class="">There seems to be a problem with the binary search to find the nearest transition times, when you are within the “fall-behind” transition. If I am in the Europe/London timezone and have a time like </div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">                    </span>"2019-10-27 01:16:46”</div><div class=""><br class=""></div><div class="">converting it to UTC is producing the same time (because it ends up finding the non-DST range.  But ONE second earlier ends up thinking it’s within the DST range, so "2019-10-27 01:16:45” ends up reporting</div><div class=""><br class=""></div><div class=""> <span class="Apple-tab-span" style="white-space:pre">                        </span>“2019-10-2 00:16:45”</div><div class=""><br class=""></div><div class="">I tried to use the gnu date command to see if I could reproduce this in a clean tz environment using the -u -d flags, and couldn’t duplicate the problems I’m seeing, so there’s a possibility that this is something I’m doing wrong.  </div><div class=""><br class=""></div><div class="">But the following experimental change in localsub makes it consistently pick the non-dst representation of the time.</div><div class=""><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">    } else {</font></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">                int        lo = 1;</font></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">                int        hi = sp->timecnt;</font></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><br class=""></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">                while (lo < hi) {</font></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">                        int        mid = (lo + hi) >> 1;</font></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><br class=""></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">                        if (t < sp->ats[mid])</font></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">                                hi = mid;</font></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">                        else        lo = mid + 1;</font></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">                }</font></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">                i = (int) sp->types[lo - 1];</font></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><b class=""><font size="2" face="sans-serif" class="">                // Check if this is a dst setting AND 't' is within the magic hour that</font></b></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><b class=""><font size="2" face="sans-serif" class="">                // replays when we fall behind.  In this case we always treat a time as</font></b></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><b class=""><font size="2" face="sans-serif" class="">                // not in the dst.</font></b></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><b class=""><font size="2" face="sans-serif" class="">                //</font></b></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><b class=""><font size="2" face="sans-serif" class="">                </font></b></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><b class=""><font size="2" face="sans-serif" class="">                if (sp->ttis[i].tt_isdst</font></b></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><b class=""><font size="2" face="sans-serif" class="">                    && (t - sp->ttis[i].tt_gmtoff) > sp->ats[lo-1])</font></b></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><b class=""><font size="2" face="sans-serif" class="">                  i = (int) sp->types[lo];</font></b></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><br class=""></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">        }</font></div></div><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><font size="2" face="sans-serif" class="">        ttisp = &sp->ttis[i];</font><font face="sans-serif" class=""> </font></div><div class=""><font face="sans-serif" class=""><br class=""></font></div></div></blockquote><font face="sans-serif" class="">Does this make any sense? </font></body></html>