timezone.go 913 B

1234567891011121314151617181920212223242526272829303132
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package storage // import "miniflux.app/v2/internal/storage"
  4. import (
  5. "fmt"
  6. "strings"
  7. )
  8. // Timezones returns all timezones supported by the database.
  9. func (s *Storage) Timezones() (map[string]string, error) {
  10. timezones := make(map[string]string)
  11. rows, err := s.db.Query(`SELECT name FROM pg_timezone_names ORDER BY name ASC`)
  12. if err != nil {
  13. return nil, fmt.Errorf(`store: unable to fetch timezones: %v`, err)
  14. }
  15. defer rows.Close()
  16. for rows.Next() {
  17. var timezone string
  18. if err := rows.Scan(&timezone); err != nil {
  19. return nil, fmt.Errorf(`store: unable to fetch timezones row: %v`, err)
  20. }
  21. if !strings.HasPrefix(timezone, "posix") && !strings.HasPrefix(timezone, "SystemV") && timezone != "localtime" {
  22. timezones[timezone] = timezone
  23. }
  24. }
  25. return timezones, nil
  26. }