timezone.go 844 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package storage
  5. import (
  6. "fmt"
  7. "github.com/miniflux/miniflux2/helper"
  8. "time"
  9. )
  10. func (s *Storage) GetTimezones() (map[string]string, error) {
  11. defer helper.ExecutionTime(time.Now(), "[Storage:GetTimezones]")
  12. timezones := make(map[string]string)
  13. query := `select name from pg_timezone_names() order by name asc`
  14. rows, err := s.db.Query(query)
  15. if err != nil {
  16. return nil, fmt.Errorf("unable to fetch timezones: %v", err)
  17. }
  18. defer rows.Close()
  19. for rows.Next() {
  20. var timezone string
  21. if err := rows.Scan(&timezone); err != nil {
  22. return nil, fmt.Errorf("unable to fetch timezones row: %v", err)
  23. }
  24. timezones[timezone] = timezone
  25. }
  26. return timezones, nil
  27. }