timezone.go 898 B

123456789101112131415161718192021222324252627282930313233343536
  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. "time"
  8. "github.com/miniflux/miniflux/timer"
  9. )
  10. // Timezones returns all timezones supported by the database.
  11. func (s *Storage) Timezones() (map[string]string, error) {
  12. defer timer.ExecutionTime(time.Now(), "[Storage:Timezones]")
  13. timezones := make(map[string]string)
  14. query := `select name from pg_timezone_names() order by name asc`
  15. rows, err := s.db.Query(query)
  16. if err != nil {
  17. return nil, fmt.Errorf("unable to fetch timezones: %v", err)
  18. }
  19. defer rows.Close()
  20. for rows.Next() {
  21. var timezone string
  22. if err := rows.Scan(&timezone); err != nil {
  23. return nil, fmt.Errorf("unable to fetch timezones row: %v", err)
  24. }
  25. timezones[timezone] = timezone
  26. }
  27. return timezones, nil
  28. }