Skip to content

Commit

Permalink
Clock matcher: add custom offset support
Browse files Browse the repository at this point in the history
  • Loading branch information
vnxme committed Aug 2, 2024
1 parent 698448b commit e91b3f3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions modules/l4clock/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,20 @@ func (m *MatchClock) Provision(_ caddy.Context) (err error) {
}

timezone := repl.ReplaceAll(m.Timezone, "")
if m.location, err = time.LoadLocation(timezone); err != nil {
return
for _, layout := range tzLayouts {
if len(layout) != len(timezone) {
continue
}
if t, e := time.Parse(layout, timezone); e == nil {
_, offset := t.Zone()
m.location = time.FixedZone(timezone, offset)
break
}
}
if m.location == nil {
if m.location, err = time.LoadLocation(timezone); err != nil {
return
}
}

return nil
Expand Down Expand Up @@ -145,6 +157,8 @@ const (
timeMin = "00:00:00"
)

var tzLayouts = [...]string{"-07", "-07:00", "-07:00:00"}

// Interface guards
var (
_ caddy.Provisioner = (*MatchClock)(nil)
Expand Down

0 comments on commit e91b3f3

Please sign in to comment.