2020-09-07 09:19:33 -05:00
|
|
|
package setting
|
|
|
|
|
2020-09-15 08:20:53 -05:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"gopkg.in/ini.v1"
|
|
|
|
)
|
|
|
|
|
2020-09-07 09:19:33 -05:00
|
|
|
type DateFormats struct {
|
|
|
|
FullDate string `json:"fullDate"`
|
|
|
|
UseBrowserLocale bool `json:"useBrowserLocale"`
|
|
|
|
Interval DateFormatIntervals `json:"interval"`
|
2020-09-15 08:20:53 -05:00
|
|
|
DefaultTimezone string `json:"defaultTimezone"`
|
2021-10-18 08:27:14 -05:00
|
|
|
DefaultWeekStart string `json:"defaultWeekStart"`
|
2020-09-07 09:19:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type DateFormatIntervals struct {
|
2022-06-29 00:39:50 -05:00
|
|
|
Millisecond string `json:"millisecond"`
|
|
|
|
Second string `json:"second"`
|
|
|
|
Minute string `json:"minute"`
|
|
|
|
Hour string `json:"hour"`
|
|
|
|
Day string `json:"day"`
|
|
|
|
Month string `json:"month"`
|
|
|
|
Year string `json:"year"`
|
2020-09-07 09:19:33 -05:00
|
|
|
}
|
|
|
|
|
2021-10-18 08:27:14 -05:00
|
|
|
const localBrowser = "browser"
|
2020-09-15 08:20:53 -05:00
|
|
|
|
2020-11-09 07:39:56 -06:00
|
|
|
func valueAsTimezone(section *ini.Section, keyName string) (string, error) {
|
2021-10-18 08:27:14 -05:00
|
|
|
timezone := section.Key(keyName).MustString(localBrowser)
|
|
|
|
if timezone == localBrowser {
|
|
|
|
return localBrowser, nil
|
2020-09-15 08:20:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
location, err := time.LoadLocation(timezone)
|
|
|
|
if err != nil {
|
2021-10-18 08:27:14 -05:00
|
|
|
return localBrowser, err
|
2020-09-15 08:20:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return location.String(), nil
|
|
|
|
}
|
|
|
|
|
2020-09-07 09:19:33 -05:00
|
|
|
func (cfg *Cfg) readDateFormats() {
|
|
|
|
dateFormats := cfg.Raw.Section("date_formats")
|
2020-09-08 04:33:04 -05:00
|
|
|
cfg.DateFormats.FullDate = valueAsString(dateFormats, "full_date", "YYYY-MM-DD HH:mm:ss")
|
2022-06-29 00:39:50 -05:00
|
|
|
cfg.DateFormats.Interval.Millisecond = valueAsString(dateFormats, "interval_millisecond", "HH:mm:ss.SSS")
|
2020-09-08 04:33:04 -05:00
|
|
|
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")
|
2020-09-07 09:19:33 -05:00
|
|
|
cfg.DateFormats.Interval.Year = "YYYY"
|
2021-07-05 07:45:36 -05:00
|
|
|
cfg.DateFormats.UseBrowserLocale = dateFormats.Key("use_browser_locale").MustBool(false)
|
2020-09-15 08:20:53 -05:00
|
|
|
|
2020-11-09 07:39:56 -06:00
|
|
|
timezone, err := valueAsTimezone(dateFormats, "default_timezone")
|
2020-09-15 08:20:53 -05:00
|
|
|
if err != nil {
|
|
|
|
cfg.Logger.Warn("Unknown timezone as default_timezone", "err", err)
|
|
|
|
}
|
|
|
|
cfg.DateFormats.DefaultTimezone = timezone
|
2021-10-18 08:27:14 -05:00
|
|
|
cfg.DateFormats.DefaultWeekStart = valueAsString(dateFormats, "default_week_start", "browser")
|
2020-09-07 09:19:33 -05:00
|
|
|
}
|