package tfelem import ( "git.swzry.com/zry/YAGTF/yagtf/utils" "strconv" "strings" "time" ) type MonthElement struct { UseMonthName bool Fill bool UseAbbr bool } func (this *MonthElement) ExpectedSize() int { if this.UseMonthName { if this.UseAbbr { return 3 } else { return 9 } } else { return 2 } } func (this *MonthElement) PrintElement(t time.Time) string { m := t.Month() if this.UseMonthName { s := m.String() if this.UseAbbr { return s[:3] } else { if this.Fill { return s + strings.Repeat(" ", 9-len(s)) } else { return s } } } else { mint := int(m) if this.Fill { return utils.GetFilledNumberWithTruncate(mint, 2) } else { return strconv.Itoa(mint) } } } func NewNumbericMonthElement(fill bool) *MonthElement { return &MonthElement{ UseMonthName: false, Fill: fill, } } func NewEnglishMonthElement(abbrevation bool, fill bool) *MonthElement { return &MonthElement{ UseMonthName: true, UseAbbr: abbrevation, Fill: fill, } }