You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
787 B

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package timeutil
  5. import (
  6. "time"
  7. "code.gitea.io/gitea/modules/setting"
  8. )
  9. var (
  10. langTimeFormats = map[string]string{
  11. "zh-CN": "2006年01月02日 15时04分05秒",
  12. "en-US": time.RFC1123,
  13. "lv-LV": "02.01.2006. 15:04:05",
  14. }
  15. )
  16. // GetLangTimeFormat represents the default time format for the language
  17. func GetLangTimeFormat(lang string) string {
  18. return langTimeFormats[lang]
  19. }
  20. // GetTimeFormat represents the
  21. func GetTimeFormat(lang string) string {
  22. if setting.TimeFormat == "" {
  23. format := GetLangTimeFormat(lang)
  24. if format == "" {
  25. format = time.RFC1123
  26. }
  27. return format
  28. }
  29. return setting.TimeFormat
  30. }