feat: add timezone support with automatic timestamp conversion

Add GetTimezone() API method and WithTimezone() client option.
When enabled, the client lazily fetches the server timezone on
first API call and converts all Timestamp fields in responses
using reflection-based struct walking.
This commit is contained in:
Oliver Jakoubek 2026-02-02 12:34:15 +01:00
commit 1fba43cf90
6 changed files with 339 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import (
"log/slog"
"net/http"
"strings"
"sync"
"time"
)
@ -19,6 +20,9 @@ type Client struct {
auth Authenticator
logger *slog.Logger
authHeaderName string // custom auth header, empty = use "Authorization"
timezone *time.Location
tzOnce sync.Once
tzEnabled bool
}
// NewClient creates a new Kanboard API client.
@ -103,3 +107,11 @@ func (c *Client) WithLogger(logger *slog.Logger) *Client {
c.logger = logger
return c
}
// WithTimezone enables automatic timestamp conversion. On the first API call,
// the client fetches the server's timezone via getTimezone and converts all
// Timestamp fields in responses to that timezone.
func (c *Client) WithTimezone() *Client {
c.tzEnabled = true
return c
}