datetime.go 804 B

1234567891011121314151617181920212223242526272829303132333435
  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. formDayFormat = "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.Language, date time.Time) string {
  18. return date.Format(dayFormat) + " " +
  19. getMonthStr(lang, date.Format(monthFormat)) + " " +
  20. date.Format(yearFormat)
  21. }
  22. func FormatDateForm(date time.Time) string {
  23. return date.Format(yearFormat) + "-" + date.Format(monthFormat) + "-" + date.Format(formDayFormat)
  24. }
  25. func getMonthStr(lang i18n.Language, month string) string {
  26. return i18n.T(lang, fmt.Sprintf("m%s", month))
  27. }