This commit is contained in:
pavel 2026-04-08 21:54:57 +02:00
commit 561ed63ac7
5 changed files with 18 additions and 3 deletions

View file

@ -4,3 +4,4 @@ SESSION_KEY=dev-session-key-change-me
APP_ENV=development
ADMIN_EMAIL=admin@superbanka.local
ADMIN_PASSWORD=admin123456
TIMEZONE=UTC

View file

@ -12,6 +12,7 @@ The app listens on `http://localhost:8080` by default.
Postgres is exposed on `localhost:5433` to avoid conflicts with any existing local instance.
The app loads `.env` automatically on startup. Existing shell environment variables still take precedence over values in `.env`.
Set `TIMEZONE` to any IANA timezone name such as `UTC` or `Europe/Prague` to control how timestamps are rendered in the UI.
Default bootstrap admin credentials:

View file

@ -14,6 +14,7 @@ type Config struct {
AppEnv string
AdminEmail string
AdminPass string
Timezone string
}
func Load() Config {
@ -28,6 +29,7 @@ func Load() Config {
AppEnv: getenv("APP_ENV", "development"),
AdminEmail: getenv("ADMIN_EMAIL", "admin@superbanka.local"),
AdminPass: getenv("ADMIN_PASSWORD", "admin123456"),
Timezone: getenv("TIMEZONE", "UTC"),
}
}

View file

@ -97,8 +97,15 @@ func NewApp(cfg config.Config) (*App, error) {
return nil, fmt.Errorf("run migrations: %w", err)
}
location, err := time.LoadLocation(cfg.Timezone)
if err != nil {
dbPool.Close()
return nil, fmt.Errorf("load timezone %q: %w", cfg.Timezone, err)
}
time.Local = location
store := db.NewStore(dbPool)
renderer, err := NewRenderer()
renderer, err := NewRenderer(location)
if err != nil {
dbPool.Close()
return nil, err

View file

@ -25,7 +25,11 @@ type Renderer struct {
templates *template.Template
}
func NewRenderer() (*Renderer, error) {
func NewRenderer(location *time.Location) (*Renderer, error) {
if location == nil {
location = time.UTC
}
funcs := template.FuncMap{
"money": platform.FormatCZK,
"dt": func(t time.Time) string {
@ -33,7 +37,7 @@ func NewRenderer() (*Renderer, error) {
return ""
}
return t.Format("02. 01. 2006 15:04")
return t.In(location).Format("02. 01. 2006 15:04")
},
}