Improve TPTiming time format error handling

This commit is contained in:
arberkatellari
2025-01-13 18:08:50 +02:00
committed by Dan Christian Bogos
parent 3acc76474d
commit 7664ffccb4
5 changed files with 42 additions and 0 deletions

View File

@@ -221,6 +221,11 @@ func (t *TPTiming) IsActiveAt(tm time.Time) bool {
return true
}
// Returns true if string can be split in 3 sperated by ":" signs. "00:00:00"
func IsTimeFormated(t string) bool {
return len(strings.Split(t, ":")) == 3
}
// Returns a time object that represents the end of the interval realtive to the received time
func (t *TPTiming) getRightMargin(tm time.Time) (rigthtTime time.Time) {
year, month, day := tm.Year(), tm.Month(), tm.Day()

View File

@@ -1180,3 +1180,17 @@ func TestGetRightMargin(t *testing.T) {
})
}
}
func TestIsTimeFormatedTrue(t *testing.T) {
timeString := "12:12:12"
if !IsTimeFormated(timeString) {
t.Error("expected time to be formated, but returned false")
}
}
func TestIsTimeFormatedFalse(t *testing.T) {
timeString := "*any"
if IsTimeFormated(timeString) {
t.Error("expected invalid time format, but returned true")
}
}

View File

@@ -273,6 +273,10 @@ func ErrNotConvertibleTF(from, to string) error {
return fmt.Errorf("%s : from: %s to:%s", ErrNotConvertibleNoCaps.Error(), from, to)
}
func ErrInvalidTime(s string) error {
return fmt.Errorf("INVALID_TIME:%s", s)
}
// NewSTIRError returns a error with a *stir_authorize prefix
func NewSTIRError(reason string) error {
return fmt.Errorf("%s: %s", MetaSTIRAuthenticate, reason)