123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package datetime
- import (
- "fmt"
- "time"
- "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/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 {
- switch lang {
- case i18n.En:
- return getMonthStr(lang, date.Format(monthFormat)) + " " +
- date.Format(dayFormat) + " " +
- date.Format(yearFormat)
- default:
- 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))
- }
|