On Mon, 14 Jul 2025 at 11:10, Jonathan Wakely <jwak...@redhat.com> wrote:
>
> On Mon, 14 Jul 2025 at 11:08, Björn Schäpers <g...@hazardy.de> wrote:
> >
> > Am 14.07.2025 um 10:20 schrieb Tomasz Kaminski:
> > >
> > >
> > > On Tue, Jul 8, 2025 at 10:48 PM Björn Schäpers wrote:
> > >     +         const auto raw_index = information.Bias / 60;
> > >     +
> > >     +         // The bias added to the local time equals UTC. And GMT+X 
> > > corrosponds
> > >     +         // to UTC-X, the sign is negated. Thus we can use the 
> > > hourly bias as
> > >     +         // an index into an array.
> > >     +         if (raw_index < 0 && raw_index >= -14)
> > >     +           {
> > >     +             static array<string_view, 14> table{
> > >     +               "Etc/GMT-1",  "Etc/GMT-2",  "Etc/GMT-3",  "Etc/GMT-4",
> > >     +               "Etc/GMT-5",  "Etc/GMT-6",  "Etc/GMT-7",  "Etc/GMT-8",
> > >     +               "Etc/GMT-9",  "Etc/GMT-10", "Etc/GMT-11", 
> > > "Etc/GMT-12",
> > >     +               "Etc/GMT-13", "Etc/GMT-14"
> > >     +             };
> > >     +             return table[-raw_index - 1];
> > >     +           }
> > >     +         else if (raw_index > 0 && raw_index <= 12)
> > >     +           {
> > >     +             static array<string_view, 14> table{
> > >
> > > This table has size 14, but only 12 entries. I do not think there are 
> > > zones
> > > past +12,
> > > but I believe size and entries should match.
> >
> > That is totally correct and this a classic copy and paste error.
> > @Jonathan: Should I correct that (and the other things you mentioned), or 
> > are
> > you doing that?
>
> I can do it before I push it (probably later today).

Hmm, we could reduce the number of guard variables for static
constructors by using a single array here, and indexing into it with
raw_index + 14.

This code is only for Windows, so we're not talking constrained
microcontrollers where we need to save resources. That can be in a
follow-up commit, if we decide it's worth doing.

> >
> > >
> > >     +               "Etc/GMT+1", "Etc/GMT+2",  "Etc/GMT+3",  "Etc/GMT+4",
> > >     +               "Etc/GMT+5", "Etc/GMT+6",  "Etc/GMT+7",  "Etc/GMT+8",
> > >     +               "Etc/GMT+9", "Etc/GMT+10", "Etc/GMT+11", "Etc/GMT+12"
> > >     +             };
> > >     +             return table[raw_index - 1];
> > >     +           }
> > >     +         return {};
> > >     +       }

Reply via email to