1package utils
2
3import (
4	"fmt"
5	t "time"
6
7	ent "repodiff/entities"
8)
9
10func TimestampSeconds() ent.RepoTimestamp {
11	return ent.RepoTimestamp(t.Now().Unix())
12}
13
14func TimestampToDate(timestamp ent.RepoTimestamp) string {
15	year, month, day := t.Unix(int64(timestamp), 0).Date()
16	return fmt.Sprintf("%04d-%02d-%02d", year, month, day)
17}
18
19// Formats a timestamp into a datetime acceptable for MySQL
20func TimestampToDataStudioDatetime(timestamp ent.RepoTimestamp) string {
21	asTime := t.Unix(int64(timestamp), 0)
22	return fmt.Sprintf(
23		"%04d%02d%02d%02d",
24		asTime.Year(),
25		asTime.Month(),
26		asTime.Day(),
27		asTime.Hour(),
28	)
29}
30