photoprism/pkg/txt/empty.go
Michael Mayer c7ad17b60c Metadata: Ignore unknown values when parsing timestamps #2510
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-07-22 12:38:25 +02:00

38 lines
788 B
Go

package txt
import (
"strings"
)
// Empty tests if a string represents an empty/invalid value.
func Empty(s string) bool {
s = strings.Trim(strings.TrimSpace(s), "%*")
if s == "" || s == "0" || s == "-1" || EmptyTime(s) {
return true
}
s = strings.ToLower(s)
return s == "nil" || s == "null" || s == "nan"
}
// NotEmpty tests if a string does not represent an empty/invalid value.
func NotEmpty(s string) bool {
return !Empty(s)
}
// EmptyTime tests if the string is empty or matches an unknown time pattern.
func EmptyTime(s string) bool {
switch s {
case "":
return true
case "0000:00:00 00:00:00", "0000-00-00 00-00-00", "0000-00-00 00:00:00":
return true
case "0001-01-01 00:00:00", "0001-01-01 00:00:00 +0000 UTC":
return true
default:
return false
}
}