12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package tfelem
- import (
- "git.swzry.com/zry/YAGTF/yagtf/utils"
- "time"
- )
- type SecondFloatPartPrecision uint8
- const (
- SFPP_Millisecond SecondFloatPartPrecision = 0
- SFPP_Microsecond SecondFloatPartPrecision = 1
- SFPP_Nanosecond SecondFloatPartPrecision = 2
- )
- type SecondFloatPartElement struct {
- Precision SecondFloatPartPrecision
- }
- func (this *SecondFloatPartElement) ExpectedSize() int {
- switch this.Precision {
- case SFPP_Millisecond:
- return 3
- case SFPP_Microsecond:
- return 6
- case SFPP_Nanosecond:
- return 9
- default:
- return 0
- }
- }
- func (this *SecondFloatPartElement) PrintElement(t time.Time) string {
- l := t.Nanosecond()
- switch this.Precision {
- case SFPP_Nanosecond:
- return utils.GetFilledNumberWithTruncate(l, 9)
- case SFPP_Microsecond:
- l = utils.IntDivWithRound(l, 1000)
- return utils.GetFilledNumberWithTruncate(l, 6)
- case SFPP_Millisecond:
- l = utils.IntDivWithRound(l, 1000000)
- return utils.GetFilledNumberWithTruncate(l, 3)
- default:
- return ""
- }
- }
- func NewSecondFloatPartElement(precision SecondFloatPartPrecision) *SecondFloatPartElement {
- return &SecondFloatPartElement{
- Precision: precision,
- }
- }
- func NewSecondFloatPartElementWithMilliSec() *SecondFloatPartElement {
- return &SecondFloatPartElement{
- Precision: SFPP_Millisecond,
- }
- }
- func NewSecondFloatPartElementWithMicroSec() *SecondFloatPartElement {
- return &SecondFloatPartElement{
- Precision: SFPP_Microsecond,
- }
- }
- func NewSecondFloatPartElementWithNanoSec() *SecondFloatPartElement {
- return &SecondFloatPartElement{
- Precision: SFPP_Nanosecond,
- }
- }
|