photoprism/pkg/txt/empty.go
Michael Mayer 4f425790ab Auth: Remember ownership of uploaded photos and albums #98 #782
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-09-30 19:15:10 +02:00

37 lines
855 B
Go

package txt
import (
"strings"
)
// Empty checks whether a string represents an empty, unset, or undefined value.
func Empty(s string) bool {
if s == "" {
return true
} else if s = strings.Trim(s, "%* "); s == "" || s == "0" || s == "-1" || EmptyTime(s) {
return true
} else if s = strings.ToLower(s); s == "nil" || s == "null" || s == "nan" {
return true
}
return false
}
// 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
}
}