1
0

2 Коммиты aff032b780 ... 1849b2fa8e

Автор SHA1 Сообщение Дата
  Paul Klumpp 1849b2fa8e cli: chatto date format configurable via CHEAPO_DATE_FORMAT (default compact 02.01.) 2 дней назад
  Paul Klumpp aff032b780 cli: print 'Free until:' timestamp as ISO-8601 (RFC3339, UTC) 2 дней назад
2 измененных файлов с 14 добавлено и 3 удалено
  1. 7 0
      .env.example
  2. 7 3
      cmd/cheapo/chatto.go

+ 7 - 0
.env.example

@@ -0,0 +1,7 @@
+# .env in the project root (godotenv). Never commit the real .env file.
+CHATTO_TOKEN="<token>"               # set by the operator
+# CHATTO_BASE_URL=https://chat.chatto.run   # optional, is the default
+
+# Date format for chatto-send output (Go time layout). Default: 02.01.
+# CHEAPO_DATE_FORMAT=02.01.2006 15:04
+CHEAPO_DATE_FORMAT=02.01.

+ 7 - 3
cmd/cheapo/chatto.go

@@ -64,13 +64,17 @@ func formatGames(games []game.Game, mode string) string {
 	b.WriteString("| Game | Store | Price | Period |\n")
 	b.WriteString("|---|---|---|---|\n")
 	for _, g := range games {
+		dateFmt := os.Getenv("CHEAPO_DATE_FORMAT")
+		if dateFmt == "" {
+			dateFmt = "02.01."
+		}
 		period := "—"
 		if g.Kind == "upcoming" && !g.StartDate.IsZero() && !g.EndDate.IsZero() {
 			period = fmt.Sprintf("from %s, until %s",
-				g.StartDate.UTC().Format("2006-01-02"),
-				g.EndDate.UTC().Format("2006-01-02"))
+				g.StartDate.Local().Format(dateFmt),
+				g.EndDate.Local().Format(dateFmt))
 		} else if !g.EndDate.IsZero() {
-			period = "until " + g.EndDate.UTC().Format("2006-01-02")
+			period = "until " + g.EndDate.Local().Format(dateFmt)
 		}
 		fmt.Fprintf(&b, "| **%s** | [%s](%s) | %s | %s |\n",
 			escapePipe(g.Title), g.Store, g.URL, priceCell(g), period)