package tfelem import ( "git.swzry.com/zry/YAGTF/yagtf/utils" "strconv" "time" ) type TimeZoneElement struct { UseAbbr bool UseUTCOffset bool Fill bool } func (this *TimeZoneElement) ExpectedSize() int { if this.UseAbbr { return 3 } else { if this.UseUTCOffset { return 5 } else { return 5 } } } func (this *TimeZoneElement) PrintElement(t time.Time) string { tzn, tzo := t.Zone() if this.UseAbbr { return tzn } else { if this.UseUTCOffset { zm := utils.IntDivWithRound(tzo, 60) zh := utils.IntDivWithRound(tzo, 3600) if zm < 0 { zm = -zm zh = -zh zhm := zm - zh*60 ztxt := zh*100 + zhm return "-" + utils.GetFilledNumberWithTruncate(ztxt, 4) } else { zhm := zm - zh*60 ztxt := zh*100 + zhm return "+" + utils.GetFilledNumberWithTruncate(ztxt, 4) } } else { if this.Fill { return utils.GetFilledNumberWithTruncate(tzo, 5) } else { return strconv.Itoa(tzo) } } } } func NewTimeZoneAbbrElement() *TimeZoneElement { return &TimeZoneElement{ UseAbbr: true, UseUTCOffset: false, Fill: false, } } func NewTimeZoneUTCOffsetElement() *TimeZoneElement { return &TimeZoneElement{ UseAbbr: false, UseUTCOffset: true, Fill: false, } } func NewTimeZoneNumbericOffsetElement(fill bool) *TimeZoneElement { return &TimeZoneElement{ UseAbbr: false, UseUTCOffset: false, Fill: fill, } }