summaryrefslogtreecommitdiffstats
path: root/utils/timezone.go
blob: ea5f1514065e666cea1f9c91f245e962d39aca36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package utils

import (
	"encoding/json"
	"io/ioutil"

	"github.com/mattermost/mattermost-server/model"
)

func LoadTimezones(fileName string) model.SupportedTimezones {
	var supportedTimezones model.SupportedTimezones

	if timezoneFile := FindConfigFile(fileName); timezoneFile == "" {
		return model.DefaultSupportedTimezones
	} else if raw, err := ioutil.ReadFile(timezoneFile); err != nil {
		return model.DefaultSupportedTimezones
	} else if err := json.Unmarshal(raw, &supportedTimezones); err != nil {
		return model.DefaultSupportedTimezones
	} else {
		return supportedTimezones
	}
}