oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package housekeeping
2
3import (
4 "testing"
5 "time"
6)
7
8// The housekeeping clock in a person's zone (paused work review N1, S5):
9// Europe/Dublin in summer, and on the two days its clocks change (last
10// Sunday of March, 01:00 UTC forward; last Sunday of October, 01:00 UTC
11// back). The day, the sweep's 03:00 and the digest's 08:00 are the
12// clock's own hours on that day, never midnight plus hours.
13func TestHousekeepingClockInDublin(t *testing.T) {
14 dublin, err := time.LoadLocation("Europe/Dublin")
15 if err != nil {
16 t.Fatal(err)
17 }
18 utc := func(s string) time.Time {
19 v, err := time.Parse(time.RFC3339, s)
20 if err != nil {
21 t.Fatal(err)
22 }
23 return v
24 }
25 for _, c := range []struct {
26 name, now, day, sweep, digest string
27 }{
28 {"summer", "2027-07-14T12:00:00Z", "2027-07-13T23:00:00Z", "2027-07-14T02:00:00Z", "2027-07-14T07:00:00Z"},
29 {"spring forward", "2027-03-28T12:00:00Z", "2027-03-28T00:00:00Z", "2027-03-28T02:00:00Z", "2027-03-28T07:00:00Z"},
30 {"fall back", "2027-10-31T12:00:00Z", "2027-10-30T23:00:00Z", "2027-10-31T03:00:00Z", "2027-10-31T08:00:00Z"},
31 {"winter", "2027-11-24T12:00:00Z", "2027-11-24T00:00:00Z", "2027-11-24T03:00:00Z", "2027-11-24T08:00:00Z"},
32 } {
33 now := utc(c.now)
34 if got := DayStart(now, dublin); !got.Equal(utc(c.day)) {
35 t.Errorf("%s: day starts %v, want %s", c.name, got, c.day)
36 }
37 if got := AtHour(now, dublin, SweepHour); !got.Equal(utc(c.sweep)) {
38 t.Errorf("%s: sweep %v, want %s", c.name, got, c.sweep)
39 }
40 if got := AtHour(now, dublin, QuietUntil); !got.Equal(utc(c.digest)) {
41 t.Errorf("%s: digest %v, want %s", c.name, got, c.digest)
42 }
43 if got := AtHour(now, dublin, SweepHour).In(dublin).Hour(); got != SweepHour {
44 t.Errorf("%s: the sweep is at %d local", c.name, got)
45 }
46 }
47 // Quiet hours (22:00 to 08:00) in Dublin's summer: 07:30 local is
48 // 06:30 UTC and still quiet; the receipt shows at 08:00 local.
49 q := QuietHours{From: 22, Until: 8}
50 at := utc("2027-07-14T06:30:00Z")
51 if !q.Quiet(at, dublin) {
52 t.Fatal("07:30 in Dublin is not quiet")
53 }
54 if v := q.VisibleAt(at, dublin); v == nil || !v.Equal(utc("2027-07-14T07:00:00Z")) {
55 t.Fatalf("visible at %v", v)
56 }
57 if q.Quiet(utc("2027-07-14T07:30:00Z"), dublin) {
58 t.Fatal("08:30 in Dublin is quiet")
59 }
60}
61