oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package thintest
2
3import (
4 "context"
5 "testing"
6 "time"
7
8 "amadan.net/oficina/equipo/internal/wire"
9)
10
11// PutTimeZone is PUT /api/v1/time-zone: the person's zone, as their
12// device says it.
13func (c *Client) PutTimeZone(ctx context.Context, zone string) (out wire.TimeZone, err error) {
14 return out, c.do(ctx, "PUT", "/api/v1/time-zone", wire.TimeZone{TimeZone: zone}, &out)
15}
16
17// localClock is a person's zone, for tests that must hold on any date:
18// at(d, h) is h o'clock d days after today, on the local clock.
19type localClock struct {
20 loc *time.Location
21 today time.Time
22}
23
24// zoneClock sets the person's zone and reads today's date in it.
25func zoneClock(t *testing.T, c *Client, ctx context.Context, zone string) localClock {
26 t.Helper()
27 if _, err := c.PutTimeZone(ctx, zone); err != nil {
28 t.Fatal(err)
29 }
30 loc, err := time.LoadLocation(zone)
31 if err != nil {
32 t.Fatal(err)
33 }
34 n := time.Now().In(loc)
35 return localClock{loc: loc, today: time.Date(n.Year(), n.Month(), n.Day(), 0, 0, 0, 0, loc)}
36}
37
38// at is h:m o'clock d days after today, on the local clock, in UTC.
39func (l localClock) at(d, h, m int) time.Time {
40 return time.Date(l.today.Year(), l.today.Month(), l.today.Day()+d, h, m, 0, 0, l.loc).UTC()
41}
42