timezone.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. "time"
  9. "miniflux.app/timer"
  10. )
  11. // Timezones returns all timezones supported by the database.
  12. func (s *Storage) Timezones() (map[string]string, error) {
  13. defer timer.ExecutionTime(time.Now(), "[Storage:Timezones]")
  14. timezones := make(map[string]string)
  15. rows, err := s.db.Query(`SELECT name FROM pg_timezone_names() ORDER BY name ASC`)
  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. if !strings.HasPrefix(timezone, "posix") && !strings.HasPrefix(timezone, "SystemV") && timezone != "localtime" {
  26. timezones[timezone] = timezone
  27. }
  28. }
  29. return timezones, nil
  30. }