datetime.go 788 B

1234567891011121314151617181920212223242526272829303132
  1. package datetime
  2. import (
  3. "fmt"
  4. "time"
  5. "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/i18n"
  6. )
  7. const (
  8. dateTimeFormat = "2006-01-02"
  9. yearFormat = "2006"
  10. monthFormat = "01"
  11. dateFormat = "02"
  12. dayFormat = "2"
  13. )
  14. func ParseDateTime(dateTime string) (time.Time, error) {
  15. return time.Parse(dateTimeFormat, dateTime)
  16. }
  17. func FormatDateStr(lang i18n.Lang, date time.Time) string {
  18. return date.Format(dayFormat) + " " + getMonthStr(lang, date.Format(monthFormat)) + " " + date.Format(yearFormat)
  19. }
  20. func FormatDateForm(date time.Time) string {
  21. return date.Format(yearFormat) + "-" + date.Format(monthFormat) + "-" + date.Format(dateFormat)
  22. }
  23. func getMonthStr(lang i18n.Lang, month string) string {
  24. return i18n.T(lang, fmt.Sprintf("m%s", month))
  25. }