package thintest import ( "context" "testing" "time" "amadan.net/oficina/equipo/internal/wire" ) // PutTimeZone is PUT /api/v1/time-zone: the person's zone, as their // device says it. func (c *Client) PutTimeZone(ctx context.Context, zone string) (out wire.TimeZone, err error) { return out, c.do(ctx, "PUT", "/api/v1/time-zone", wire.TimeZone{TimeZone: zone}, &out) } // localClock is a person's zone, for tests that must hold on any date: // at(d, h) is h o'clock d days after today, on the local clock. type localClock struct { loc *time.Location today time.Time } // zoneClock sets the person's zone and reads today's date in it. func zoneClock(t *testing.T, c *Client, ctx context.Context, zone string) localClock { t.Helper() if _, err := c.PutTimeZone(ctx, zone); err != nil { t.Fatal(err) } loc, err := time.LoadLocation(zone) if err != nil { t.Fatal(err) } n := time.Now().In(loc) return localClock{loc: loc, today: time.Date(n.Year(), n.Month(), n.Day(), 0, 0, 0, 0, loc)} } // at is h:m o'clock d days after today, on the local clock, in UTC. func (l localClock) at(d, h, m int) time.Time { return time.Date(l.today.Year(), l.today.Month(), l.today.Day()+d, h, m, 0, 0, l.loc).UTC() }