timezone.go 950 B

123456789101112131415161718192021222324252627282930313233
  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 // import "miniflux.app/storage"
  5. import (
  6. "fmt"
  7. "strings"
  8. )
  9. // Timezones returns all timezones supported by the database.
  10. func (s *Storage) Timezones() (map[string]string, error) {
  11. timezones := make(map[string]string)
  12. rows, err := s.db.Query(`SELECT name FROM pg_timezone_names() ORDER BY name ASC`)
  13. if err != nil {
  14. return nil, fmt.Errorf(`store: unable to fetch timezones: %v`, err)
  15. }
  16. defer rows.Close()
  17. for rows.Next() {
  18. var timezone string
  19. if err := rows.Scan(&timezone); err != nil {
  20. return nil, fmt.Errorf(`store: unable to fetch timezones row: %v`, err)
  21. }
  22. if !strings.HasPrefix(timezone, "posix") && !strings.HasPrefix(timezone, "SystemV") && timezone != "localtime" {
  23. timezones[timezone] = timezone
  24. }
  25. }
  26. return timezones, nil
  27. }