diff options
| author | 2025-08-18 19:28:18 +0700 | |
|---|---|---|
| committer | 2025-08-18 19:28:18 +0700 | |
| commit | 6401cf603f598a8008c69a14fe58f460009180a7 (patch) | |
| tree | e275408d111e0fd98f46826ca6cabba6aafdd763 /internal/router/api-v1-tz.go | |
| parent | 188d24d6cb7a1d753898b340359e3fcfaf426433 (diff) | |
| parent | f3b5c8136217fd57f7ae948a153f3510558a139d (diff) | |
| download | web-0.6.0.tar.gz web-0.6.0.zip | |
v0.6.0v0.6.0
- feat: add map page
- feat: use webp of various sizes (320/560/800/1200/1600w) as thumbnails
- feat: fixate gallery divs to viewport measures
- feat: make thumbnails square
- feat: remove recreating gallery on window resize
- refactor: replace gap with margins
- refactor: more line height in gallery captions
- refactor: have routes in separate files
Diffstat (limited to 'internal/router/api-v1-tz.go')
| -rw-r--r-- | internal/router/api-v1-tz.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/router/api-v1-tz.go b/internal/router/api-v1-tz.go new file mode 100644 index 0000000..4e4e462 --- /dev/null +++ b/internal/router/api-v1-tz.go @@ -0,0 +1,37 @@ +package router + +import ( + "log/slog" + "time" + + "github.com/gofiber/fiber/v2" +) + +func Api_V1_TZ() func(c *fiber.Ctx) error { + return func(c *fiber.Ctx) error { + timestampString := c.Query("timestamp") + tz := c.Query("tz") + + loc, err := time.LoadLocation(tz) + if err != nil { + loc = time.UTC + slog.Warn("unable to parse a client timezone, defaulting to UTC", slog.String("error", err.Error()), slog.String("tz", tz)) + } + + var format string + var timestamp time.Time + for _, format = range []string{"2006-01-02 15:04:05 -07:00", time.RFC3339} { + if timestamp, err = time.Parse(format, timestampString); err == nil { + break + } + } + + c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8) + + if err != nil { + return c.Status(fiber.StatusBadRequest).SendString("invalid timestamp format") + } + + return c.Status(fiber.StatusOK).SendString(timestamp.In(loc).Format(format)) + } +} |