mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 12:14:08 -06:00
a9faab6b09
* Add global week start option to shared preferences * Add default_week_start to configuration docs * Add week start option to dashboards * Add week start argument to tsdb time range parser * Fix strict check issues * Add tests for week start * Change wording on default_week_start documentation Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update week_start column to be a nullable field Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> * Update configuration to include browser option * Update WeekStartPicker container selector Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com> * Add menuShouldPortal to WeekStartPicker to remove deprecation warning Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com> * Add inputId to WeekStartPicker * Use e2e selector on WeekStartPicker aria-label * Simplify WeekStartPicker onChange condition * Specify value type on WeekStartPicker weekStarts * Remove setWeekStart side effect from reducer * Fix updateLocale failing to reset week start * Store week start as string to handle empty values Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com> Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package setting
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gopkg.in/ini.v1"
|
|
)
|
|
|
|
type DateFormats struct {
|
|
FullDate string `json:"fullDate"`
|
|
UseBrowserLocale bool `json:"useBrowserLocale"`
|
|
Interval DateFormatIntervals `json:"interval"`
|
|
DefaultTimezone string `json:"defaultTimezone"`
|
|
DefaultWeekStart string `json:"defaultWeekStart"`
|
|
}
|
|
|
|
type DateFormatIntervals struct {
|
|
Second string `json:"second"`
|
|
Minute string `json:"minute"`
|
|
Hour string `json:"hour"`
|
|
Day string `json:"day"`
|
|
Month string `json:"month"`
|
|
Year string `json:"year"`
|
|
}
|
|
|
|
const localBrowser = "browser"
|
|
|
|
func valueAsTimezone(section *ini.Section, keyName string) (string, error) {
|
|
timezone := section.Key(keyName).MustString(localBrowser)
|
|
if timezone == localBrowser {
|
|
return localBrowser, nil
|
|
}
|
|
|
|
location, err := time.LoadLocation(timezone)
|
|
if err != nil {
|
|
return localBrowser, err
|
|
}
|
|
|
|
return location.String(), nil
|
|
}
|
|
|
|
func (cfg *Cfg) readDateFormats() {
|
|
dateFormats := cfg.Raw.Section("date_formats")
|
|
cfg.DateFormats.FullDate = valueAsString(dateFormats, "full_date", "YYYY-MM-DD HH:mm:ss")
|
|
cfg.DateFormats.Interval.Second = valueAsString(dateFormats, "interval_second", "HH:mm:ss")
|
|
cfg.DateFormats.Interval.Minute = valueAsString(dateFormats, "interval_minute", "HH:mm")
|
|
cfg.DateFormats.Interval.Hour = valueAsString(dateFormats, "interval_hour", "MM-DD HH:mm")
|
|
cfg.DateFormats.Interval.Day = valueAsString(dateFormats, "interval_day", "YYYY-MM-DD")
|
|
cfg.DateFormats.Interval.Month = valueAsString(dateFormats, "interval_month", "YYYY-MM")
|
|
cfg.DateFormats.Interval.Year = "YYYY"
|
|
cfg.DateFormats.UseBrowserLocale = dateFormats.Key("use_browser_locale").MustBool(false)
|
|
|
|
timezone, err := valueAsTimezone(dateFormats, "default_timezone")
|
|
if err != nil {
|
|
cfg.Logger.Warn("Unknown timezone as default_timezone", "err", err)
|
|
}
|
|
cfg.DateFormats.DefaultTimezone = timezone
|
|
cfg.DateFormats.DefaultWeekStart = valueAsString(dateFormats, "default_week_start", "browser")
|
|
}
|