package datetime

import (
	"fmt"
	"time"

	"git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/service/i18n"
)

const (
	dateTimeFormat = "2006-01-02"
	yearFormat     = "2006"
	monthFormat    = "01"
	formDayFormat  = "02"
	dayFormat      = "2"
)

func ParseDateTime(dateTime string) (time.Time, error) {
	return time.Parse(dateTimeFormat, dateTime)
}

func FormatDateStr(lang i18n.Language, date time.Time) string {
	return date.Format(dayFormat) + " " +
		getMonthStr(lang, date.Format(monthFormat)) + " " +
		date.Format(yearFormat)

}

func FormatDateForm(date time.Time) string {
	return date.Format(yearFormat) + "-" + date.Format(monthFormat) + "-" + date.Format(formDayFormat)
}

func getMonthStr(lang i18n.Language, month string) string {
	return i18n.T(lang, fmt.Sprintf("m%s", month))
}
