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