oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package kernel
2
3import (
4 "crypto/sha256"
5 "encoding/json"
6 "fmt"
7 "time"
8)
9
10func JobTopic(teamID string, id int64) string {
11 kind := "job"
12 if id == 0 {
13 kind = "collection"
14 }
15 raw, _ := json.Marshal(struct {
16 Kind string
17 Team string
18 Job int64
19 }{kind, teamID, id})
20 return fmt.Sprintf("jobs/%x", sha256.Sum256(raw))
21}
22
23func ReadTime(v any) time.Time {
24 if t, ok := v.(time.Time); ok {
25 return t
26 }
27 for _, f := range []string{time.RFC3339Nano, "2006-01-02 15:04:05.999999999-07:00", "2006-01-02 15:04:05.999999999+00:00", "2006-01-02 15:04:05.999999999"} {
28 if t, e := time.Parse(f, fmt.Sprint(v)); e == nil {
29 return t
30 }
31 }
32 return time.Time{}
33}
34func WeekStart(now time.Time) time.Time {
35 n := now.UTC()
36 day := (int(n.Weekday()) + 6) % 7
37 return time.Date(n.Year(), n.Month(), n.Day()-day, 0, 0, 0, 0, time.UTC)
38}
39