hour.go 682 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package tfelem
  2. import (
  3. "git.swzry.com/zry/YAGTF/yagtf/utils"
  4. "strconv"
  5. "time"
  6. )
  7. type HourElement struct {
  8. Fill bool
  9. Use12hFormat bool
  10. }
  11. func (this *HourElement) ExpectedSize() int {
  12. return 2
  13. }
  14. func (this *HourElement) PrintElement(t time.Time) string {
  15. h := t.Hour()
  16. if h > 12 && this.Use12hFormat {
  17. h -= 12
  18. }
  19. if this.Fill {
  20. return utils.GetFilledNumberWithTruncate(h, 2)
  21. } else {
  22. return strconv.Itoa(h)
  23. }
  24. }
  25. func NewHour24hElement(fill bool) *HourElement {
  26. return &HourElement{
  27. Use12hFormat: false,
  28. Fill: fill,
  29. }
  30. }
  31. func NewHour12hElement(fill bool) *HourElement {
  32. return &HourElement{
  33. Use12hFormat: true,
  34. Fill: fill,
  35. }
  36. }